san*_*ndy 8 java post exception-handling spring-mvc modelandview
我在场景中抛出异常.由哪个处理@ExceptionHandler.但是当抛出异常时,它说Request方法'POST'不支持
控制器代码
@RequestMapping(value = "abcd", method = {RequestMethod.POST,RequestMethod.GET })
public String testAbc(Model model, HttpServletRequest request) throws Exception {
//some piece of code
if(someCondition)
throw new Exception("No data found with id ");
}
Run Code Online (Sandbox Code Playgroud)
ExceptionController类中的代码
@ExceptionHandler(Exception.class)
public ModelAndView handleException(Exception ex, HttpServletRequest request, HttpServletResponse response) {
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("errorMessage", ex.getMessage());
modelAndView.addObject("errorDetails", ExceptionUtils.getStackTrace(ex));
modelAndView.setViewName("forward:errorPage");
return modelAndView;
}
Run Code Online (Sandbox Code Playgroud)
不知道我做错了什么.
似乎处理的控制器/errorPage不接受请求方法POST.在您的@ExceptionHandler方法中,您通过将视图名称设置为来向该页面转发forward:errorPage.
你能确认errorPage控制器是否处理POST方法吗?
| 归档时间: |
|
| 查看次数: |
1807 次 |
| 最近记录: |