HTML页面:
<html>
<body>
<form action="http://localhost:8080/项目名/controller/方法名" method="POST" enctype="multipart/form-data">
yourfile: <input type="file" name="myfile"/><br/>
<input type="submit" value="aaa"/>
</form>
</body>
</html>
Controller方法:
@RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
@ResponseBody
public String fileUpload(HttpServletRequest request, HttpServletResponse response,
@RequestParam MultipartFile myfile) throws IOException {
// 用来检测程序运行时间
long startTime = System.currentTimeMillis();
try {
logger.info("文件长度: " + myfile.getSize());
logger.info("文件类型: " + myfile.getContentType());
logger.info("文件名称: " + myfile.getName());
logger.info("文件原名: " + myfile.getOriginalFilename());
logger.info("========================================");
String realPath="E:\\test\\"+fwbs+"\\"+year+"\\"+month+"\\";
FileUtils.copyInputStreamToFile(myfile.getInputStream(), new File(""E:\\test\\, “xxx.zip”));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
long endTime = System.currentTimeMillis();
System.out.println("上传的运行时间:" + String.valueOf(endTime - startTime) + "ms");
return msg;
}