1、禁止tomcat目录浏览,将listings设为false
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>
org.apache.catalina.servlets.DefaultServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
2、配置web.xml
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
3、http error codes 参考
HTTP Error Codes and what they mean
Web servers will use the following Error Codes when something goes awry. Knowing what they mean enables you to fix the problem, or create custom error pages.
The status codes are returned to the client the request (typically an Internet Browser) and also recorded in the server's log file. Theses error codes are encoded into decimal ranges:
Error Code Range Type of Error Code
Error Code Range Type of Error Code
100 to 199 Informational status codes, rarely used - and generally only written to server logs.
200 to 299 Successful, only 200 frequently used - and generally only written to server logs.
300 to 399 Warning - but the request may still be satisfiable.
400 to 499 Client Error, the request was invalid in some way.
500 to 599 Server Error, the server could not fulfil the (valid) request.
本文介绍如何通过设置Tomcat的DefaultServlet参数来禁止目录浏览,并配置web.xml中的错误页面以统一错误显示。同时提供了HTTP状态码含义说明,帮助理解不同错误码的作用。

3284

被折叠的 条评论
为什么被折叠?



