Objective
Previously with ASP. Mvc+uploadify upload files, recently learned SPRINGMVC, so use springmvc+uploadify to do an upload file demo.
Just started to submit the form form, in the controller action with @requestparam multipartfile file will be able to get upload files information. After I directly use uploadify upload, interface did not make any adjustments, upload the process of reporting http400, the client's request does not meet the requirements of the interface, form Post submitted times the text parameter is in form data mode, Instead of uploadify, the parameter format is the way the request payload, so the interface is rewritten as a multipartservletrequest.
Development environment
SpringMVC4, Uploadify,
If you upload a file, you also need to download commons-fileupload, and also download Common-io, common-logging
Project structure
Normal form Upload
<form action= /user/index Span style= "color: #800000;" > " Method=" post " Enctype=" multipart/form-data ><input type=" file name=" file ><input type=" Span style= "color: #800000;" >submit value=" upload /></form>
@RequestMapping ("Upload") public @ResponseBody String upload (@RequestParam multipartfile file) throws IOException { String path =request.getsession (). Getservletcontext (). Getrealpath ("Upload"); File File=new file (Path,file.getoriginalfilename ()); File.transferto (file); Save The file return "/success"; }
Uploadify Uploading Files
<%@ page contenttype= "Text/html;charset=utf-8" language= "java"%>
Interface
@RequestMapping (value = "/upload", method = requestmethod.post) public @ResponseBody String upload (HttpServletRequest re Quest, HttpServletResponse Response) {String path =request.getsession (). Getservletcontext (). Getrealpath ("Upload"); Multiparthttpservletrequest multiparthttpservletrequest= (multiparthttpservletrequest) request; map<string,multipartfile> map = Multiparthttpservletrequest.getfilemap (); System.out.println ("Path:" +path); File File=new file (path); if (!file.exists ()) {file.mkdirs (); } try{for (map.entry<string,multipartfile> Entity:map.entrySet ()) {multipartfile mu Ltipartfile=entity.getvalue (); File FF = new file (Path,multipartfile.getoriginalfilename ()); Multipartfile.transferto (FF); } return "Success"; }catch (Exception e) {e.printstacktrace (); return "error"; } }
Referencehttp://smilease.iteye.com/blog/1693898
Http://www.cnblogs.com/fjsnail/p/3491033.html
Springmvc+jquery.uploadify Uploading Files