这是我目前所拥有的: Controller :
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。
我错过了什么?
谢谢:)
最佳答案
我认为你需要返回你想要显示的 View 。
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public String handleAllExceptions(Exception e) {
return "error.jsp"; /* use the correct view name */
}
@查看:Spring 3 controller exception handler implementation problems 一些例子
关于java - @ResponseStatus 和 web.xml <错误页面>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4760683/