SSH web.xml配置
web.xml配置檔案內容有如下部分內容:
(1)引入spring配置
<!-- 設定監聽器自動載入spring配置檔案開始 -->
<context-param>
<param-name>contextConfigLocation</param-name><!-- ContextLoaderListener載入時,會查詢名為contextConfigLocation的初始化引數。因此,配置<context-param..>時應指定引數名為contextConfigLocation -->
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 設定監聽器自動載入spring配置檔案結束 -->
(2)引入struts配置(過濾器)
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<!-- 定義Struts2的CleanUp Filter開始 --><!-- 延長action中屬性的生命週期,包括自定義屬性,以便在jsp頁面中進行訪問,讓 actionContextcleanup過濾器來清除屬性,不讓action自己清除 -->
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 定義Struts2的CleanUp Filter結束 -->
(3)對jsp頁面的配置也可以在web.xml裡配置
如每個jsp頁裡頂部引入的標頭檔案,也可以在web.xml裡配置
<jsp-config>
<taglib>
<taglib-uri>http://struts.apache.org/tags-bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://struts.apache.org/tags-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://struts.apache.org/tags-logic</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://struts.apache.org/tags-nested</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://struts.apache.org/tags-tiles</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>
</jsp-config>