SWFUpload简单使用样例 Java版(JSP)
SWFUpload官方的样例都是PHP的,在这里提供一个Java版的最简单的使用样例,使用JSP页面完毕全部操作。
实现上传,分为三步:
1、JavaScript设置SWFUpload部分(与官方样例类似):
- var upload;
- window.onload = function() {
- upload = new SWFUpload({
- // 处理文件上传的url
- upload_url: "${pageContext.request.contextPath}/swfupload/example.jsp?upload=1",
- // 上传文件限制设置
- file_size_limit : "10240", // 10MB
- file_types : "*.jpg;*.gif;*.png", //此处也能够改动成你想限制的类型,比方:*.doc;*.wpd;*.pdf
- file_types_description : "Image Files",
- file_upload_limit : "0",
- file_queue_limit : "1",
- // 事件处理设置(全部的自己定义处理方法都在handler.js文件中)
- file_dialog_start_handler : fileDialogStart,
- file_queued_handler : fileQueued,
- file_queue_error_handler : fileQueueError,
- file_dialog_complete_handler : fileDialogComplete,
- upload_start_handler : uploadStart,
- upload_progress_handler : uploadProgress,
- upload_error_handler : uploadError,
- upload_success_handler : uploadSuccess,
- upload_complete_handler : uploadComplete,
- // 按钮设置
- button_image_url : "swfupload/xpbutton.png", // 按钮图标
- button_placeholder_id : "spanButtonPlaceholder",
- button_width: 61,
- button_height: 22,
- // swf设置
- flash_url : "swfupload/swfupload.swf",
- custom_settings : {
- progressTarget : "fsUploadProgress",
- cancelButtonId : "btnCancel"
- },
- // Debug 设置
- debug: false
- });
- }
2、页面显示部分:
- <div class="flash" id="fsUploadProgress"></div>
- <div style="padding-left: 5px;">
- <span id="spanButtonPlaceholder"></span>
- <input id="btnCancel" type="button" value="取消" onclick="cancelQueue(upload);"
- disabled="disabled" style="margin-left: 2px; height: 22px; font-size: 8pt;" />
- </div>
3、Java处理文件上传部分:
- String uploadSign = request.getParameter("upload");
- String rootPath = request.getParameter("rootPath");
- String path = request.getParameter("path");
- if(rootPath == null) rootPath = "";
- rootPath = rootPath.trim();
- if(rootPath.equals("")){
- rootPath = application.getRealPath("/swfupload/files");
- }
- if(path == null) {
- path = rootPath;
- }else{
- path = new String(Base64.decodeBase64(path.getBytes()));
- }
- //上传操作
- if(null != uploadSign && !"".equals(uploadSign)){
- FileItemFactory factory = new DiskFileItemFactory();
- ServletFileUpload upload = new ServletFileUpload(factory);
- //upload.setHeaderEncoding("UTF-8");
- try{
- List items = upload.parseRequest(request);
- if(null != items){
- Iterator itr = items.iterator();
- while(itr.hasNext()){
- FileItem item = (FileItem)itr.next();
- if(item.isFormField()){
- continue;
- }else{
- //以当前精确到秒的日期为上传的文件的文件名称
- SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddkkmmss");
- String type = item.getName().split("\\.")[1];//获取文件类型
- File savedFile = new File(path,sdf.format(new Date())+"."+type);
- item.write(savedFile);
- }
- }
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- }
SWFUpload简单使用样例 Java版(JSP)的更多相关文章
- Introspector(内省)简单演示样例 与 简单应用
简单演示样例: package com.asdfLeftHand.test; import java.beans.BeanDescriptor; import java.beans.BeanInfo; ...
- JBoss 系列九十六:JBoss MSC - 简介及一个简单演示样例
什么是 JBoss MSC JBoss MSC 即 JBoss Modular Service Container,是第三代 JBoss 产品 JBoss 7和WildFfly的内核,JBoss MS ...
- Thrift的安装和简单演示样例
本文仅仅是简单的解说Thrift开源框架的安装和简单使用演示样例.对于具体的解说,后面在进行阐述. Thrift简述 ...
- [hadoop系列]Pig的安装和简单演示样例
inkfish原创,请勿商业性质转载,转载请注明来源(http://blog.csdn.net/inkfish ).(来源:http://blog.csdn.net/inkfish) Pig是Yaho ...
- Android中关于JNI 的学习(零)简单的样例,简单地入门
Android中JNI的作用,就是让Java可以去调用由C/C++实现的代码,为了实现这个功能.须要用到Anrdoid提供的NDK工具包,在这里不讲怎样配置了,好麻烦,配置了好久. . . 本质上,J ...
- Android通过startService播放背景音乐简单演示样例
关于startService的基本使用概述及其生命周期可參见博客<Android中startService的使用及Service生命周期>. 本文通过播放背景音乐的简单演示样例,演示sta ...
- 一则简单演示样例看Oracle的“无私”健壮性
Oracle的强大之处就在于他能总帮助让你选择正确的运行计划,即使你给了它错误的指示. 实验: 1. 创建測试表: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZ ...
- scrapy爬虫学习系列二:scrapy简单爬虫样例学习
系列文章列表: scrapy爬虫学习系列一:scrapy爬虫环境的准备: http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_python_00 ...
- 使用CEF(二)— 基于VS2019编写一个简单CEF样例
使用CEF(二)- 基于VS2019编写一个简单CEF样例 在这一节中,本人将会在Windows下使用VS2019创建一个空白的C++Windows Desktop Application项目,逐步进 ...
随机推荐
- Visual Studio2013创建、公布监控Windows Azure网站
原文 Visual Studio2013创建.公布监控Windows Azure网站 随着Visual Studio 2013的发布,现在我们可以在Visual Studio内部实现Windows A ...
- javascript 中 undefined 和 null 区别
1.相同点 如果我们直接用 undefined == null 比较他们是相等的返回的将是 true. 2.区别 当我们用undefined === null 比较的时候最后返回的将是 false. ...
- Boost::thread库的使用
阅读对象 本文假设读者有几下Skills [1]在C++中至少使用过一种多线程开发库,有Mutex和Lock的概念. [2]熟悉C++开发,在开发工具中,能够编译.设置boost::thread库. ...
- hbase memstorelab
关于MemStore的补充 在通过HStore.add向store中加入�一个kv时,首先把数据写入到memstore中.这一点没有什么说明: publiclongadd(finalKeyValue ...
- 使用JDBC调用数据库的存储过程
本篇讲述如何使用JDBC来调用MySQL数据库中的存储过程.建议在学习如何使用JDBC调用存储过程前,请先了解如何在数据库中使用存储过程. 存储过程是指在数据库系统中,一组为了完成特定功能的SQL语句 ...
- delphi中一切皆指针
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Form ...
- eclipse发布项目报错:Multiple Contexts hava a path of “/xxx“
你的位置:首页 > Java编程 > eclipse发布项目报错:Multiple Contexts hava a path of “/xxx“ eclipse发布项目报错:Multipl ...
- 去掉Enter字符(\r)的几个方法
数据:test.txt: f1:f2:f3:# Shell: #!/bin/bash while read line do echo $line result1=$(echo $line|awk -F ...
- javascript实现图片无缝滚动(scrollLeft的使用方法介绍)
<!DOCTYPE html > <html> <head> <meta http-equiv="Content-Type" conten ...
- R语言与数据分析之六:时间序列简介
今年在某服装企业蹲点了4个多月,之间非常长一段时间在探索其现货和期货预測.时间序列也是做销售预測的首选,今天和小伙伴分享下时间序列的基本性质和怎样用R来挖据时间序列的相关属性. 首先读入一个时间序列: ...