tomcat配置錯誤頁面
如果希望定制工程的錯誤頁面,有兩種定義方式:
- 在web.xml中添加<error-page>
- 設置Host的errorReportValveClass屬性
兩種設置方法的區別在於:第一種是當前web應用生效,第二種是整個虛擬主機生效
除非錯誤頁與web應用無關,否則不推薦配置成第二種。還有一個不適用此配置的原因是errorReportValveClass屬性定義的錯誤頁會出入服務器細節。不安全。
第一種定義方式配置方法
[root@iZzm446eh1ux98Z webapps]# vim myapp/WEB-INF/web.xml
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"
metadata-complete="true">
<error-page>
<error-code>404</error-code>
<location>/err4.html</location> ##其中"/" 對應的是Context標簽中定義的docBase的位置
</error-page>
<error-page>
<error-code>500</error-code>
<location>/err5.html</location>
</error-page>
</web-app>
編輯錯誤頁
[root@iZzm446eh1ux98Z webapps]# vim myapp/err4.html Not Found
訪問測試

