Java @ResponseStatus和web.xml<;错误页面>;

Java @ResponseStatus和web.xml<;错误页面>;,java,spring-mvc,web.xml,Java,Spring Mvc,Web.xml,以下是我目前掌握的情况: 控制器: public abstract class MyController { @ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public void handleAllExceptions(Exception e) { // stuff } } 和my web.xml: <error-page>

以下是我目前掌握的情况: 控制器:

public abstract class MyController {
   @ExceptionHandler(Exception.class)
   @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
   public void handleAllExceptions(Exception e) {
      // stuff
   }
}
和my web.xml:

<error-page>
  <error-code>500</error-code>
  <location>/error.htm</location>
</error-page>

500
/error.htm
当发生意外异常时,句柄工作,事情完成,但我不会重定向到/error.htm

相反,我仍然在同一页上,但是apache打印了一个错误500

我错过了什么


谢谢:)

我想您需要返回要显示的视图

@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public String handleAllExceptions(Exception e) {
  return "error.jsp"; /* use the correct view name */
}
@请参阅:有关一些示例

return“redirect:/error.htm”;使用重定向:它可以工作!谢谢:)