Loading...

Plupload+easyui+springmvc实现批量上传

demo下载(java项目):http://pan.baidu.com/s/1ntmoGEd

可兼容所有常用浏览器,当前版本为V1.5.4,如果不兼容,肯定是你没有调试好啊

1.jsp代码

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<link rel="stylesheet" href="${ctx}/static/js/plupload/queue/css/jquery.plupload.queue.css" type="text/css"></link>
<script type="text/javascript" src="${ctx}/static/js/plupload/plupload.js"></script>
<script type="text/javascript" src="${ctx}/static/js/plupload/plupload.html4.js"></script>
<script type="text/javascript" src="${ctx}/static/js/plupload/plupload.html5.js"></script>
<script type="text/javascript" src="${ctx}/static/js/plupload/plupload.flash.js"></script>
<script type="text/javascript" src="${ctx}/static/js/plupload/zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/static/js/plupload/queue/jquery.plupload.queue.js"></script>
<script type="text/javascript">
    var ctx='${ctx}'+'static/js/';
    var files = [];
    var errors = [];
    var type = 'file';
    var max_file_size = '10mb';
    $(document).ready(function(){
        var filters = {title : "文档", extensions : "xml"};
        $("#uploader").pluploadQueue($.extend({
            runtimes : 'flash,html4,html5',
            url : 'localUpLoadProgram',
            max_file_size : max_file_size,
            file_data_name:'file',
            unique_names:true,
            filters : [filters],
            flash_swf_url : ctx+'plupload/plupload.flash.swf',
            init:{
                FileUploaded:function(uploader,file,response){
                    if(response.response){
                        var rs = $.parseJSON(response.response);
                        if(rs.status){
                            files.push(file.name);
                        }else{
                            errors.push(file.name);
                        }
                    }
                },
                UploadComplete:function(uploader,fs){
                    //var e= errors.length ? ",失败"+errors.length+"个("+errors.join("、")+")。" : "。";
                   // alert("上传完成!共"+fs.length+"个。成功"+files.length+e);
                    //target.window("close");
                }
            }
        },(false ? {chunk_size:'1mb'} : {})));
    });
</script>
<div id="uploader">&nbsp;</div>

 2.java代码

    @RequestMapping("/localUpLoadProgram")
    public void localUpLoadProgram(
            @RequestParam("file") CommonsMultipartFile file,HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        HttpSession session = request.getSession();
        UserBean user = (UserBean) session.getAttribute(ConstantsUtil.SESSION_USER);
        String ip = IpUtils.getIpAddr(request);
        String fileName = file.getOriginalFilename();
        InputStream inputFile = file.getInputStream();
        // 获取文件后缀名
        String endName = fileName.substring(fileName.lastIndexOf(".") + 1,
                fileName.length());
        if ("xml".equals(endName)) {
           saveLocalDate(inputFile, user, ip);
        }
        //上传成功

          Map<String, Object> resultMap = new HashMap<String, Object>();
          resultMap.put("status", true);
          String json = JSONObject.toJSONString(resultMap);
          response.getWriter().write(json);

    }

 

 
posted @ 2015-06-11 19:50  微笑阳光哈*_*  阅读(1397)  评论(0编辑  收藏  举报