【问题标题】:@ResponseStatus and web.xml <error-page>@ResponseStatus 和 web.xml <error-page>
【发布时间】:2011-01-21 15:42:44
【问题描述】:

这是我目前所拥有的: 控制器:

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

还有我的 web.xml:

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

当发生意外异常时,句柄工作,工作完成,但我没有重定向到 /error.htm

相反,我仍在同一页面上,但 apache 打印了错误 500。

我错过了什么?

谢谢:)

【问题讨论】:

    标签: java spring-mvc web.xml


    【解决方案1】:

    我认为您需要返回要显示的视图。

    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public String handleAllExceptions(Exception e) {
      return "error.jsp"; /* use the correct view name */
    }
    

    @see: Spring 3 controller exception handler implementation problems 一些例子

    【讨论】:

    • return "redirect:/error.htm";使用重定向:它有效!谢谢:)
    猜你喜欢
    • 2017-11-11
    • 2014-12-02
    • 2012-11-07
    • 1970-01-01
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多