1. JSP page code
<formenctype=""Multipart/form-data "Method= "POST"> <inputtype= "File"name= "File"> <inputtype= "Submit"value= "Upload" ></form>
2, controller in the code
@RequestMapping ("/sysfindheimingdan/excelmobanupload") @ResponseBody Public voidUploadexcelmodel (httpservletrequest request,httpservletresponse response)throwsException {//Start uploading ExcelMultiparthttpservletrequest multipartrequest =(multiparthttpservletrequest) request; Multipartfile Multipartfile= Multipartrequest.getfile ("File"); String SourceName= Multipartfile.getoriginalfilename ();//Original file nameLong size =multipartfile.getsize (); String FileType= Sourcename.substring (Sourcename.lastindexof ("."))); System.out.println ("The uploaded file name is:" +sourcename+ "type:" +filetype+ "Size:" +size); String Base= Request.getsession (). Getservletcontext (). Getrealpath ("/upload//"); Gets the path of the file upload, in the upload under WebApp.=NewFile (base); if(!file.exists ()) {File.mkdirs (); } String Path=base + File.separator +SourceName; Multipartfile.transferto (NewFile (path)); }
Springmvc uploading an Excel or CSV file