web.xml中經常使用配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
     <!--spring的監聽器-->
     <listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<!-- context-param 元素用來設定web站臺的環境參數(context)-->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:com/itheima11/gyl/spring/applicationContext.xml</param-value>
	</context-param>
	
	<!--struts2過濾器-->
 
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
    <!--歡迎頁面設置-->
	<welcome-file-list>
		<welcome-file>login.jsp</welcome-file>
	</welcome-file-list>


</web-app>

1. spring與容器整合: 使用listenerjava

<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<!-- context-param 元素用來設定web站臺的環境參數(context)-->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:com/itheima11/gyl/spring/applicationContext.xml</param-value>
</context-param>

2. 若要添加自定義過濾器:web

<!-- 自定義過濾器,要放置到struts2的過濾器的上面 -->
  	<filter>
  		<filter-name>SystemFilter</filter-name>
  		<filter-class>cn.itcast.elec.util.SystemFilter</filter-class>
  	</filter>
  	<filter-mapping>
  		<filter-name>SystemFilter</filter-name>
  		<url-pattern>*.jsp</url-pattern>
  		<url-pattern>*.do</url-pattern>
  	</filter-mapping>

3. struts2與容器的整合是經過過濾器整合的spring

<!-- 添加struts2的過濾器,這是struts2執行的核心 -->
  	<filter>
  		<filter-name>struts2</filter-name>
  		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  	</filter>
  	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>*.jsp</url-pattern>
		<url-pattern>*.do</url-pattern>
	</filter-mapping>

4. springMVC與容器的整合: 用serverletapache

<servlet>
		<servlet-name>springMvc</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<!--springMVC配置文件-->
      <init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring/ApplicationContext-mvc.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>springMvc</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
相關文章
相關標籤/搜索