用upoadify插件在spring mvc 框架下上传文件,总是报错500(internal server error)求指导~
前端代码:
<link rel="stylesheet" href="uploadify/uploadify.css"type="text/css"> <script src="assets/js/jquery-1.11.1.min.js"></script><script type="text/javascript" src="uploadify/swfobject.js"></script><script type="text/javascript" src="uploadify/jquery.uploadify.js"></script>
$(document).ready(function(){ $("#mediaID01").uploadify({ 'swf' : 'uploadify/uploadify.swf', 'uploader' : '../WxController/saveMediaInServer',//后台处理的请求 'cancelImg' : 'img/uploadify-cancel.png', 'folder' : 'newWxQyServer/img/',//您想将文件保存到的路径 'queueID' : 'fileQueue',//与下面的id对应 'queueSizeLimit' : 5, 'fileDesc' : 'Image Files (*.jpg;*.jpeg;*.gif;*.png)', 'fileExt' : '*.jpg;*.jpeg;*.gif;*.png', //控制可上传文件的扩展名,启用本项时需同时声明fileDesc 'auto' : false, 'multi' : true, 'simUploadLimit' : 2, 'buttonText' : '选择图片', 'buttonImg':'', 'method':'post', 'removeCompleted':false,});
<div id="fileQueue"></div> <input type="file" name="uploadify" id="mediaID01" /> <p><a href="javascript:jQuery('#mediaID01').uploadify('upload','*');">上传</a> </p>
后台代码:
@RequestMapping(value = "/saveMediaInServer",method = RequestMethod.POST) @ResponseBody public List<String> saveMediaInServer(HttpServletRequest request, HttpServletResponse response,@RequestParam(value = "formData", required = false) String formData){ MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; List<String> responseStr= new ArrayList<String>(); Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); // 创建文件夹 Map<String, Object> type = JSON.parseObject(formData, new TypeReference<Map<String, Object>>(){}); Date now=new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); String filePath = "/upload/"+type.get("typeName")+"/"+dateFormat.format(now); String path=request.getSession().getServletContext().getRealPath(filePath); File file = new File(path); if (!file.exists()) { file.mkdirs(); } for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { // 上传文件 MultipartFile mf = entity.getValue(); String filename=String.valueOf(System.currentTimeMillis()) + (int)(Math.random()*1000000); File uploadFile = new File(path + filename); try { FileCopyUtils.copy(mf.getBytes(), uploadFile); responseStr.add("上传成功"); } catch (IOException e) { responseStr.add("上传失败"); e.printStackTrace(); } } return responseStr;
求指导,感激不尽!
查看完整描述