1. 添加依赖包maven
commons-fileupload commons-fileupload 1.3.2
2. 配置注入
3. html
4. js ajax
5. java后台
@RequestMapping(value="logFile.do",method=RequestMethod.POST) @ResponseBody public String logFile(@RequestParam("logFile")MultipartFile logFile,@RequestParam("param1")String param1,@RequestParam("param2")String param2) throws IOException { String filename = logFile.getOriginalFilename();//获取上传文件的文件名 InputStream file = null; try { file = logFile.getInputStream(); } catch (IOException e) { e.printStackTrace(); } InputStreamReader inputStreamReader = new InputStreamReader(file,"utf-8"); BufferedReader bf = new BufferedReader(inputStreamReader); String newLine = ""; while((newLine = bf.readLine()) != null){ if(newLine.equals("")){ }else { System.out.print("\n newLine = "+newLine); } } System.out.print("\n\n\n filename = "+filename); System.out.print("\n\n\n param1 = "+param1); System.out.print("\n\n\n param2 = "+param2); return "上传成功"; }