springmvc(7) 文件上传
2020-12-13 02:32
标签:get return upload path turn 实现 byte span 文件 1.通过commons-fileupload来实现:导入jar包commons-fileupload和commons-io 2.配置springmvc:配置解析器: 3.编写上传处理器代码: 4.jsp页面: springmvc(7) 文件上传 标签:get return upload path turn 实现 byte span 文件 原文地址:https://www.cnblogs.com/yuby/p/11042364.html
@RequestMapping("/upload")
public String fileupload(@RequestParam("file") CommonsMultipartFile file, HttpServletRequest request) throws IOException {
//获取文件名
// file.getOriginalFilename();
String path ="/fileupload";
InputStream is = file.getInputStream();
OutputStream os = new FileOutputStream(new File(path,file.getOriginalFilename()));
int len=0;
byte[] buffer = new byte[400];
while ((len = is.read(buffer)) != -1){
os.write(buffer,0,len);
}
os.close();
is.close();
return "index.jsp";
}