1. 程式人生 > >Tomcat學習—Tomcat的web.xml配置檔案

Tomcat學習—Tomcat的web.xml配置檔案

今天開始學習Tomcat的配置檔案,自己學習和上網檢視整理web.xml 的筆記!

1:web.xml配置簡介:
(1)、預設(歡迎)檔案的設定
 在\conf\web.xml中,<welcome-file-list>與IIS中的預設檔案意思相同。

<span style="font-size:18px;"><welcome-file-list>
  <welcome-file>index.html</welcome-file>
  <welcome-file>index.htm</welcome-file>
  <welcome-file>index.jsp</welcome-file>
</welcome-file-list></span>

(2)、報錯檔案的設定
<span style="font-size:18px;"><error-page>
 <error-code>404</error-code>
 <location>/notFileFound.jsp</location>
</error-page>
<error-page>
 <exception-type>java.lang.NullPointerException</exception-type>
 <location>/null.jsp</location>
</error-page></span>

如果某檔案資源沒有找到,伺服器要報404錯誤,按上述配置則會呼叫\webapps\ROOT\notFileFound.jsp。
如果執行的某個JSP檔案產生NullPointException ,則會呼叫\webapps\ROOT\null.jsp
 
(3)、會話超時的設定
設定session 的過期時間,單位是分鐘;
<span style="font-size:18px;"><session-config>
 <session-timeout>30</session-timeout>
</session-config></span>
(4)、過濾器的設定
<span style="font-size:18px;"><filter>
filter-name>FilterSource</filter-name>
<filter-class>project4. FilterSource </filter-class>
</filter>
<filter-mapping>
<filter-name>FilterSource</filter-name>
<url-pattern>/WwwServlet</url-pattern>
(<url-pattern>/haha/*</url-pattern>)
</filter-mapping></span>

過濾:
1) 身份驗證的過濾Authentication Filters
2) 日誌和稽核的過濾Logging and Auditing Filters
3) 圖片轉化的過濾Image conversion Filters
4) 資料壓縮的過濾Data compression Filters
5) 加密過濾Encryption Filters
6) Tokenizing Filters
7) 資源訪問事件觸發的過濾Filters that trigger resource access events XSL/T 過濾XSL/T filters
8) 內容型別的過濾Mime-type chain Filter 注意監聽器的順序,如:先安全過濾,然後資源,
然後內容型別等,這個順序可以自己定。