Recent projects have used the file from local to server functionality. In fact, in order to solve the current browser does not support getting local file full path. Had to think of the fixed directory uploaded to the server, so that the project to obtain files, so that the program supports Excel batch import data.
<form method= "POST" enctype= "Multipart/form-data" action= "in the foreground interface. /manage/excelimport.do "> Please select File: <input type=" file "name=" Excelfile "> <input type=" Submit "value=" Import "Onclic k= "return Impexcel ();" /></form>action get data from the foreground and save/** * Excel import File * @return * @throws IOException */@RequestMapping ("/usermanager/ Excelimport.do ") public string Excelimport (string filepath,multipartfile excelfile,httpservletrequest request) throws Ioexception{log.info ("<<<<<<action:{} method:{} start>>>>>>", "Usermanager", " Excelimport "); if (excelfile! = null) {String filename=excelfile.getoriginalfilename (); String A=request.getrealpath ("u/cms/www/201509"); Savefilefrominputstream (Excelfile.getinputstream (), Request.getrealpath ("u/cms/www/201509"), filename);// Save the path to the server}log.info ("<<<<<<action:{} method:{} end>>>>>>", "Usermanager", " Excelimport "); return" ";} /** * Convert Multipartfile to file and save to a place on the server */public void SavefilefromiNputstream (InputStream stream,string path,string savefile) throws ioexception{FileOutputStream fs=new FileO Utputstream (path + "/" + SaveFile); System.out.println ("------------" +path + "/" + SaveFile); byte[] buffer =new byte[1024*1024]; int bytesum = 0; int byteread = 0; while ((Byteread=stream.read (buffer))!=-1) {bytesum+=byteread; Fs.write (Buffer,0,byteread); Fs.flush (); } fs.close (); Stream.Close ();}
Upload Java files to the server