现在的位置: 首页 > 综合 > 正文

禁止tomcat 目录浏览以及设置友好错误页面

2012年10月09日 ⁄ 综合 ⁄ 共 1400字 ⁄ 字号 评论关闭

 

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.

抱歉!评论已关闭.