spring web.xml 配置详解

web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app  xmlns:xs="http://www.jboss.org/j2ee/schema"  
       xs:schemaLocation="http://www.jboss.org/j2ee/schema/jboss_5_0.xsd"  
             version="5.0">
    <display-name>spring</display-name>
	
	<!-- web.xml 的加载顺序是:context-param -> listener -> filter -> servlet ,
	而同个类型之间的实际程序调用的时候的顺序是根据对应的 mapping 的顺序进行调用的 -->
	
	<!-- spring上下文载入监听器,确保web服务启动时,spring已经完成初始化 -->
	<listener>
	  	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<listener>
   		<listener-class>org.springframework.web.context.request.RequestContextListener </listener-class>
 	</listener>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:Application-Context-*.xml</param-value>
	</context-param>  
<!--- 
<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/Application-Context-*.xml</param-value>
	</context-param>  

-->
	
	
	<filter>
		<filter-name>encodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
		<init-param>
			<param-name>ForceEncoding</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>
  
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<servlet>
		<servlet-name>springMvc3</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:Application-Context-Servlet.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
  
    <!-- 会话超时配置(单位为分钟) -->
	<session-config> 
	    <session-timeout>120</session-timeout> 
	</session-config>
  
  
	<servlet-mapping>     
		<servlet-name>default</servlet-name>    
		<url-pattern>*.jpg</url-pattern>       
	</servlet-mapping>      
	<servlet-mapping>         
		<servlet-name>default</servlet-name>      
		<url-pattern>*.js</url-pattern>      
	</servlet-mapping>      
	<servlet-mapping>          
		<servlet-name>default</servlet-name>         
		<url-pattern>*.css</url-pattern>        
	</servlet-mapping>   
	<servlet-mapping>
		<servlet-name>springMvc3</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
  
	<welcome-file-list>
		<welcome-file>/index.html</welcome-file>
	</welcome-file-list>
	
   	<!-- 过滤器filter,可以做登录验证等,具体业务具体应用,所有请求都经该过滤器过滤-->
	<!--<filter>
		<filter-name>frameworkFilter</filter-name>
		<filter-class>com.tutu.eproduct.filter.FrameworkFilter</filter-class>
		<init-param>
			<param-name>exception</param-name>
			<param-value>.css,.png,.jpg,.js,.gif,/index.jsp,/out.jsp,login_system.jsp,/login.jsp</param-value>
		</init-param>
		<init-param>
			<param-name>baseUrlStatic</param-name>
			<param-value>/static</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>frameworkFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>-->
	<!-- 登陆验证 结束 -->
  
	<!-- 通过错误码来配置error-page ,配置了当系统发生404错误时,跳转到错误处理页面NotFound.jsp。 -->
	<error-page> 
	    <error-code>404</error-code> 
	    <location>/page404.html</location> 
	</error-page> 
	<!--  通过异常的类型配置error-page ,配置了当系统发生java.lang.NullException(即空指针异常)时,跳转到错误处理页面error.jsp  -->
	<error-page> 
	    <exception-type>java.lang.NullPointerException</exception-type> 
	    <location>/WEB-INF/jsp/error.jsp</location> 
	</error-page>
  
</web-app>

猜你喜欢

转载自lovemojienv.iteye.com/blog/2295749