java web

java web开发的web.xml常规配置:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

	<display-name>mini-web</display-name>
	<!-- Spring ApplicationContext配置文件的路径,可使用通配符,多个路径用,号分隔
		此参数用于后面的Spring Context Loader -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
			classpath*:/applicationContext*.xml
		</param-value>
	</context-param>

	<!-- Filter 定义  -->
	<!-- Character Encoding filter -->
	<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>


	<!-- Struts2 filter -->
	<filter>
		<filter-name>struts2CleanupFilter</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
	</filter>
	<filter>
		<filter-name>struts2Filter</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>



	<!-- 登陆过滤器 判断是否登录 -->
 <filter>
  <filter-name>sysFilter</filter-name>
  <filter-class>com.magnus.core.filter.SysUserFilter</filter-class>
  <!-- 如果没有登录 跳转的页面 -->
  <init-param>
   <param-name>redirect</param-name>
   <param-value>/index.html</param-value>
   </init-param>
   <!-- 不需要匹配的链接 -->
   <init-param>
   <param-name>noincludes</param-name>
   <param-value>login.jsp;index.html;login.do</param-value>
  </init-param>
 </filter>

	<!-- Filter 映射 -->
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	 <filter-mapping>
	  <filter-name>sysFilter</filter-name>
	   <url-pattern>*.do</url-pattern>
	   <dispatcher>REQUEST</dispatcher>
	   <dispatcher>FORWARD</dispatcher>
	 </filter-mapping>
	<filter-mapping>
	  <filter-name>sysFilter</filter-name>
	   <url-pattern>*.jsp</url-pattern>
	   <dispatcher>REQUEST</dispatcher>
	   <dispatcher>FORWARD</dispatcher>
	 </filter-mapping>
	 
	 
	<filter-mapping>
		<filter-name>struts2Filter</filter-name>
		<url-pattern>*.do</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
	</filter-mapping>
	 
	<filter-mapping>
		<filter-name>struts2CleanupFilter</filter-name>
		<url-pattern>*.do</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
	</filter-mapping>

	<servlet>
	<servlet-name>ConfigServlet</servlet-name>
		<servlet-class>com.magnus.core.servlet.ConfigServlet</servlet-class>
		<init-param>
			<param-name>configFile</param-name>
			<param-value>/WEB-INF/classes/application.properties</param-value>
		</init-param>
		<load-on-startup>9</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>ConfigServlet</servlet-name>
		<url-pattern>/refreshcfg</url-pattern>
	</servlet-mapping>

	<!--Spring的ApplicationContext 载入 -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<!-- Spring 刷新Introspector防止内存泄露 -->
	<listener>
		<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
	</listener>
	
	<!-- 单用户登录 session变更监听器 -->
	<listener>
	       <listener-class>com.magnus.core.filter.SessionListener</listener-class>
	</listener>

	<!-- session超时定义,单位为分钟 -->
	<session-config>
		<session-timeout>20</session-timeout>
	</session-config>
	<welcome-file-list>
	<welcome-file>index.html</welcome-file>
	</welcome-file-list>
	
	<error-page>
	<error-code>404</error-code>
	<location>/404.jsp</location>
	</error-page>
	
	
</web-app>

 

你可能感兴趣的:(Java Web)