我在监狱长那里有这个:
@RequestMapping(
value = "/update",
params = {"new_profile_image"},
method = RequestMethod.POST)
public ModelAndView updateUserProfileImage(
@RequestParam(value = "new_profile_image") CommonsMultipartFile newProfileImage,
ModelMap model) {
System.out.println("controller executed!");
if(newProfileImage != null && !newProfileImage.isEmpty()) {
updateService.updateUserProfileImage(newProfileImage.getBytes());
}
return new ModelAndView("redirect:/users/my_profile");
}在jsp文件中:
<form action="<c:url value='/users/update?${_csrf.parameterName}=${_csrf.token}' />" method="post" enctype="multipart/form-data">
<input name="new_profile_image" type="file" id="new_profile_image">
<button type="submit" class="btn btn-primary">Update</button>
</form>当我提交一张图片时
白线错误页此应用程序没有/error的显式映射,因此您认为这是一种退步。
2月8日(星期六) 19: 08 :10 CST 2020有一个意外的错误(type=Bad请求,status=400)。未能将“java.lang.String”类型的值转换为所需的类型'java.lang.Long';嵌套异常为java.lang.NumberFormatException: For input string:"update“
"controller executed!"字符串从未出现在控制台中。我在value = "/update"注释中通过value = "/updateImage"更改了action="<c:url value='/users/update?${_csrf.parameterName}=${_csrf.token}' />",在action="<c:url value='/users/updateImage?${_csrf.parameterName}=${_csrf.token}' />"中更改了action="<c:url value='/users/update?${_csrf.parameterName}=${_csrf.token}' />",并将错误消息编码为nested exception is java.lang.NumberFormatException: For input string: "updateImage"。
我不知道出了什么问题,在eclipse的控制台中也没有显示任何例外。
编辑:我忘记说控制器具有类级别的RequestMapping("/users")。
现在,我用value = "/updateImage"更改了控制器value = "/updateImage",但是在jsp页面中保留了action="<c:url value='/users/update?${_csrf.parameterName}=${_csrf.token}' />",错误仍然是:
白线错误页此应用程序没有/error的显式映射,因此您认为这是一种退步。
2月8日(星期六) 19: 08 :10 CST 2020有一个意外的错误(type=Bad请求,status=400)。未能将“java.lang.String”类型的值转换为所需的类型'java.lang.Long';嵌套异常为java.lang.NumberFormatException: For input string:"update“
我想请求甚至没有到达控制器。
发布于 2020-02-09 22:58:28
我最终通过从params中删除@RequestMapping属性来解决这个问题。因此,控制器的结尾是:
@RequestMapping(
value = "/updateImage",
method = RequestMethod.POST)
public ModelAndView updateUserProfileImage(
@RequestParam(value = "new_profile_image", required = true) CommonsMultipartFile newProfileImage,
ModelMap model) {
System.out.println("controller executed!");
if(newProfileImage != null && !newProfileImage.isEmpty()) {
updateService.updateUserProfileImage(newProfileImage.getBytes());
}
return new ModelAndView("redirect:/users/my_profile");
}我在其他方法中使用了post请求的params属性,而且它可以工作,我猜这里的问题与请求是多部分请求有关。但我不知道真正的问题是什么。
https://stackoverflow.com/questions/60132960
复制相似问题