在Spring framework中,有许多处理异常(尤其是404错误)的方法.
首先,你仍然可以
error-page在web.xml中使用标签,并自定义错误页面。这是一个例子。
其次,可以
@ExceptionHandler对所有控制器使用一个,如下所示:
@ControllerAdvicepublic class ControllerAdvisor { @ExceptionHandler(NoHandlerFoundException.class) public String handle(Exception ex) { return "404";//this is view name }}为此,请将
web.xml中的
throwExceptionIfNoHandlerFound属性设置为
true DispatcherServlet:
<init-param> <param-name>throwExceptionIfNoHandlerFound</param-name> <param-value>true</param-value></init-param>
你还可以将一些对象传递到错误视图



