捕捉 404500 错误,自定义Tomcat错误页面

xiaoxiao2026-03-15  11

当服务器出现404、500错误时候希望能够给用户友好的现实界面 只需要在项目的web.xml中添加一些配置 <!-- 400错误 --><error-page><error-code>400</error-code><location>/error.jsp</location></error-page><!-- 404 页面不存在错误 --><error-page><error-code>404</error-code><location>/error.jsp</location></error-page><!-- 500 服务器内部错误 --><error-page><error-code>500</error-code><location>/error.jsp</location></error-page><!-- java.lang.Exception异常错误,依据这个标记可定义多个类似错误提示 --><error-page><exception-type>java.lang.Exception</exception-type><location>/error.jsp</location></error-page><!-- java.lang.NullPointerException异常错误,依据这个标记可定义多个类似错误提示 --><error-page><exception-type>java.lang.NullPointerException </exception-type><location>/error.jsp</location></error-page><error-page><exception-type>javax.servlet.ServletException</exception-type><location>/error.jsp</location></error-page> 今天配置的时候发现,没有办法生效。 网上收集可能有以下原因: 1.使用 tomcat 服务器 2.tomcat服务器版本 3.浏览器问题 4.IE的设置 5.错误页本身的大小 一一排除,自己犯了一个比较粗心的错误,文件后缀名要和filter定义一致 error.jsp--->error.jsf 相关资源:java 面试题 总结
转载请注明原文地址: https://www.6miu.com/read-5045948.html

最新回复(0)