java uploadify 下载_java uploadify 实现文件上传

1.web端使用uploadify插件 下载地址:http://www.uploadify.com/wp-content/uploads/files/uploadify.zip

web页面代码:

导入部分:

js代码部分:

$function(){

$("#file_upload").uploadify({

'auto' : false,// 关闭自动提交

'multi' : false,

'queueSizeLimit' : 1,

'fileTypeDesc' : '支持格式:zip',// 文件类型

'fileTypeExts' : '*.zip',// 文件后缀

'formData' : {'paramname1':'paramvalue1','paramname...':'paramvalue...'},// 提交时跟上去的参数

'fileObjName': 'files',

'fileSizeLimit' :'200MB',

//'removeTimeout': 1,// 从界面上移除的时间设置

"buttonImage": path+'manage/plugin/uploadify/img/add_Flie.png',

'swf': path+'manage/plugin/uploadify/uploadify.swf',

'uploader': path+'jsonmanager/doArticle.action',

'onQueueComplete' : function(queueData) {

$('#file_upload').uploadify('disable', false);

$('.upload_btn').attr('disabled', false);

},

'onUploadSuccess' : function(file, data, response) {

},

'onUploadStart': function(file) {

$('#file_upload').uploadify('disable', true);

$('.upload_btn').attr('disabled', true);

}

});

}

页面调用部分:

请求的java代码:

提交时的参数

private List files = new ArrayList();

private List filesFileName = new ArrayList();

private List filesContentType = new ArrayList();

处理代码:

try {

HttpServletResponse response = ServletActionContext.getResponse();

HttpServletRequest request = ServletActionContext.getRequest();

Long size = Long.parseLong(request.getHeader("Content-Length"));

StringBuffer ss = new StringBuffer();//存放返回的内容

for (int i = 0; i

String type = filesContentType.get(i);

String name = filesFileName.get(i);

int index = name.lastIndexOf(".");//原名称里倒 数第一个"."在哪里

String ext = name.substring(index+1); //取得后缀,及"."后面的字符

String tempFileName = name.substring(0, index);

byte data[] = new byte[1024 * 1024]; // 用于存放流数据

File file = new File(Utils.SPECIAL_ZIP_ADDRESS,tempFileName + "." + ext); // 新建文件 Utils.SPECIAL_ZIP_ADDRESS 服务器存放地址路径

//上传的文件存在时删除之前的专题文件

OutputStream fileOutputStream = null;

InputStream in = null;

try {

fileOutputStream = new FileOutputStream(file); // 创建文件流

in = new FileInputStream(files.get(i));

int bytesRead = 0;

while ((bytesRead = in.read(data)) > 0) {

fileOutputStream.write(data, 0, bytesRead); // 写入文件流

}

} catch (RuntimeException e) {

e.printStackTrace();

} finally{

if(fileOutputStream != null){

fileOutputStream.close();

fileOutputStream = null;

}

if(in != null){

in.close();

in = null;

}

}

}

}

response.setCharacterEncoding("utf-8");

response.getWriter().write(ss.toString());

response.getWriter().close();

} catch (Exception e) {

exceptionHandler(e);

}

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2012-10-19 17:03

浏览 2817

评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值