如何在 web.xml 中指定除 404 和 500 之外的常见错误页面
How to specify common error page excluding 404 and 500 in web.xml
我已经在 web.xml 中为 404 和 500 错误页面设计了两个网页
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/error/404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/error/500.jsp</location>
</error-page>
我想针对所有其他错误重定向到预先指定的页面。
请帮忙。
谢谢
这个应该够用了,再加上客户错误相关的页面很少,可以添加默认页面。因此,除 404、500 之外的所有错误都将被重定向到通用页面 error.html
<error-page>
<location>/error.html</location>
</error-page>
或更多自定义,使用 Exception class,也可以是您的自定义异常 class。
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.html</location>
</error-page>
所以代码变成,
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/error/404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/error/500.jsp</location>
</error-page>
<error-page>
<location>/error.html</location>
</error-page>
我已经在 web.xml 中为 404 和 500 错误页面设计了两个网页
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/error/404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/error/500.jsp</location>
</error-page>
我想针对所有其他错误重定向到预先指定的页面。
请帮忙。
谢谢
这个应该够用了,再加上客户错误相关的页面很少,可以添加默认页面。因此,除 404、500 之外的所有错误都将被重定向到通用页面 error.html
<error-page>
<location>/error.html</location>
</error-page>
或更多自定义,使用 Exception class,也可以是您的自定义异常 class。
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.html</location>
</error-page>
所以代码变成,
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/error/404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/error/500.jsp</location>
</error-page>
<error-page>
<location>/error.html</location>
</error-page>