java-SpringMVC 后台怎么获取前台jsp页面中file中的文件
2个回答
展开全部
@RequestMapping("presentAction/addPicture")
public void addPicture(HttpSession session,HttpServletRequest request,HttpServletResponse response,
@RequestParam(value = "presentId", required = true) int presentId)
{
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
// 获得文件:
MultipartFile file = multipartRequest.getFile("up_img");
if (!file.isEmpty()) {
try {
// 文件保存路径
String filePath = request.getSession().getServletContext().getRealPath("/uploadImages")+"/"
+ file.getOriginalFilename();
// 转存文件
String path2="uploadImages/"+ file.getOriginalFilename();
System.out.println(filePath);
presentService.addPicture(path2,presentId);
file.transferTo(new File(filePath));
hashMap.put("code", "200");
printe(response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询