Listener、Filter以及Servlet中的url-pattern

1.Listener
1) 概念以及分类
Listener,监听器,可以实现对ServeltContext生命周期中初始化和销毁的监听,也可以实现对ServletContextAttribute、ServletRequestAttribute等属性变更事件的监听。Listener是基于观察者模式实现的,目前Servlet中定义了6种两类Listener,EvenListenter类型的ServletContextAttributeListener ServletRequestAttributeListener ServletRequestListener HttpSessionAttributeListener 以及基于LifecycleListeners类型的ServletContextListener HttpSessionListener。实际上这6个Listener都继承了EvenListener,并且都定义了各自需要的方法。如下表所示:
这里写图片描述
这里写图片描述
上面这些Listener基本涵盖了整个Servlet中你可能感兴趣的每种事情。这些Listener的实现类可以配置在web.xml中的listener标签中;当然也可以在应用程序中动态的添加Listener,需要注意的是ServletContextListener在容器启动之后就不能再添加新的,因为它所监听的事件不会再出现了。
2) Listener应用实例
Spring的org.springframework.web.context.ContextLoaderListener就是实现了ServeltContextListener,用于在容器启动时初始化Spring容器。在ContextLoaderListener中的contextInitialized()方法中,完成Spring容器的初始化,这个方法的参数是ServletContextEvent对象,可以通过这个对象的getServletContext()方法拿到ServletContext;有几种方法可以加载Spring容器,如果在web.xml中配置了名字为contextConfigLocation的context-param则会通过这里面配置xml文件加载Spring容器,如果没有配置,则会到/WEB-INF/下面查找默认的applicationContext.xml文件。
另外一个应用就是在配置Log4jConfigListener,这个Listener也就是继承了ServletContextListener,可以实现在springContext初始化之前设置好log4j的各项配置,便于其它组件输出日志使用.在contextInitialized初始化方法中会读取context-param中配置的”log4jConfigLocation”属性,然后通过其作为log4j配置文件的位置,如果是xml文件则通过Log4j的DOMConfigurator.configure()配置,如果是properties文件则可以通过PropertyConfigurator.configure方法来进行初始化,另外从源码看到,可以通过”log4jRefreshInterval”来配置读取文件的刷新时间.
需要注意的是,如果配置的其它ServletContextListener需要用到log4j输出日志,那么Log4jConfigListener应该作为第一个Listener进行配置.

2.Filter
1)概念
对从客户端向服务器端发送的请求进行过滤,也可以对服务器端返回的响应进行处理。它使用户可以改变一个request和修改一个 response.。Filter 不是一个servlet,它不能产生一个response,但是它能够在一个request到达servlet之前预处理request,也可以在 response离开servlet时处理response。换句话说,filter其实是客户端与servlet中间的一个传递者,并且它可以对要传递 的东西进行修改。
这里写图片描述
2) 工作流程

  • 当客户端发生请求后,在HttpServletRequest 到达Servlet 之前,过滤器拦截客户的HttpServletRequest 。
  • 根据需要检查HttpServletRequest ,也可以修改HttpServletRequest 头和数据。
  • 在过滤器中调用doFilter方法,对请求放行。请求到达Servlet后,对请求进 行处理并产生HttpServletResponse发送给客户端。
  • 在HttpServletResponse 到达客户端之前,过滤器拦截HttpServletResponse
  • 根据需要检查HttpServletResponse ,可以修改HttpServletResponse 头和数据。
  • 最后,HttpServletResponse到达客户端。

3) 如何实现一个Filter
Servlet API定义了Filter接口,自定义编写的Filter都需要实现这个Filter,准确的来说是实现其中的三个方法。

  • init(FilterConfig):初始化接口,在用户自定义的Filter初始化时被调用,它与Servelt的init方法的作用是一样的,FilterConfig与ServletConfig也类似,除了能取到ServletContext对象之外,还能获取在filter下配置的init-param参数。
  • doFilter(ServletRequest,ServletResponse,FilterChain):在每个用户的请求进来时,这个方法都会被调用,并在Servlet的service()方法之前被调用。而这个方法参数中的FilterChain对象代表了当前的整个请求链,所以通过FilterChain.doFilter()可以将请求继续传递下去。如果想拦截这个请求,可以不调用FilterChain.doFilter,那么这个请求就会直接返回了。所以Filter是一种责任链设计模式。
  • destory:当Filter对象被销毁时,这个方法被调用。注意的是当web容器调用这个方法之后,容器会再调用一次doFilter方法。

下面的代码展示了一个简单Filter的实现:

package com.meituan.lkl.filter;

import javax.servlet.*;
import java.io.IOException;

public class MyFirstFilter implements Filter {

    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init: " + filterConfig.getServletContext().getInitParameter("test-context-param"));
        System.out.println("init: " + filterConfig.getInitParameter("test-param"));
        System.out.println("init: " + filterConfig.getFilterName());
        System.out.println("MyFirstFilter init");
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        String name = request.getParameter("name");
        System.out.println("doFilter name=" + name);
        chain.doFilter(request, response);
        String contextType = response.getContentType();
        System.out.println("response:" + contextType);
    }

    public void destroy() {
        System.out.println("destroy");
    }
}

这里还需要重点介绍下doFilter()方法中的FilterChain参数。Filter类的核心其实就是这个在Filter之间进行传递的FilterChain对象,在其内部的filters数组中保存了最终到Servlet对象的所有Filter对象。在FilterChain链上每执行一个Filter对象,数组的当前计数都会加1,直到计数等于数组的长度,当FilterChain上所有的Filter对象都执行完成之后,就会执行最终的Servlet。所以在FilterChain对象中也会持有Servelt对象的引用。
另外上面还出现了FilterConfig对象,这个对象代表Filter的配置,它里面封装了ServletContext对象的引用以及在web.xml中配置的一些初始化参数。下面是其对外提供的几个方法:

  • String getFilterName():得到filter的名称。
  • String getInitParameter(String name): 返回在部署描述中指定名称的初始化参数的值。如果不存在返回null.
  • Enumeration getInitParameterNames():返回过滤器的所有初始化参数的名字的枚举集合。
  • ServletContext getServletContext():返回Servlet上下文对象的引用。

4)web.xml中配置Filter
上面实现了自定义的Filter之后,如果想要真正起到作用,需要在web.xml中配置filter和filter-mapping元素对编写的Filter类进行注册并设置它所能拦截的资源。下面就是一个配置示例:

<filter>
        <filter-name>testFilter</filter-name>
        <filter-class>com.meituan.lkl.filter.MyFirstFilter</filter-class>
        <init-param>
            <param-name>test-param</param-name>
            <param-value>test-param</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>testFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

5) Filter链
上面在讲FilterChain对象时就已经提到了多个Filter的情况,如果配置一组过滤器对某些web资源进行拦截,那么这组过滤器就称为过滤器链。Filter执行的顺序就是在web.xml中配置他们的顺序。能依次执行的原理参见对FilterChain的解释。
这里写图片描述

3.Servlet中的url-pattern
在web.xml中的servlet-mapping和filter-mapping都有url-pattern配置项,它们的作用是否执行这个Servlet和Filter.
Filter的url-pattern匹配是在创建FilterChain对象时进行的,它把所有定义的Filter的url-pattern与当前的URL匹配,如果匹配成功就将当前filter保存在filters数组中,然后在FilterChain中依次调用。而Servlet的url匹配是在请求对象创建时进行,创建请求时需要根据请求的url决定哪个Servlet来处理这个请求。
在web.xml加载时,会首先检查url-pattern配置是否符合规则,这个检查是在StandardContext的validateURLPattern方法中检查的,如果检查不成功,Context容器启动会失败,并报java.lang.IllegalArgumentException:Invalidurl-pattern /a.html in Servlet mapping错误。
url-pattern的解析规则,对Servlet和Filter是一样的,匹配的规则有如下三种:

  • 精确匹配:如/foo.html只会匹配foo.html这个URL
  • 路径匹配:如/foo/*会匹配以foo为前缀的URL
  • 后缀匹配:如*.html会匹配所有以.html为后缀的URL
    所有像/foo/、/.html和 /foo这些url形式都是错误的。
    一个请求可以匹配多个Filter,但是只能匹配Servelt,所以在定义了多个Servelt的情况下,会按次序进行匹配:首先精确匹配,如定义了两个Servlet,Servlet1为/foo.html,Servlet2为/,请求URL为http://localhost/foo.html,那么只会有Servlet1会匹配。如果精确匹配不成功,那么会使用第二个原则”最长路径匹配”,如Servlet1为/foo/,Servlet2为/ *,请求的URL为http://localhost/foo/foo.html,那么Servlet1匹配成功;如果都不行,那么则使用后缀匹配,但一次请求只会成功匹配到一个Servlet。
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:beans.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.css</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.gif</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.jpg</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.png</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>*.mp3</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.mp4</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.ttf</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.woff</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.woff2</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.ppt</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.doc</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.docx</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.xls</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.xlsx</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.zip</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.rar</url-pattern> </servlet-mapping> <filter> <filter-name>Set Character Encoding</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> </filter> <filter-mapping> <filter-name>Set Character Encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>wangzhan/index.jsp</welcome-file> </welcome-file-list> </web-app>
09-09
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name>spring</display-name> <!-- 加载Spring配置文件 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/spring.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> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- Spring监听--> <listener> <description>Spring监听器</description> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 防止Spring内存溢出监听--> <listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </listener> <!-- Spring MVC --> <servlet> <servlet-name>SpringMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <description>SpringMVC</description> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- 本次需要做的配置,注意位置,要放在配置springmvc的url-pattern之前 --> <!-- 表示当程序加载符合这些路径的资源时,不会通过dispatchservlet --> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.js</url-pattern> <url-pattern>*.css</url-pattern> <url-pattern>*.html</url-pattern> <url-pattern>/upload/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>SpringMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- Session超时时间 --> <!-- <session-config> <session-timeout>15</session-timeout> </session-config> --> </web-app>
06-14
<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>web application framework</display-name> <resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/waf</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> <session-config> <session-timeout>60</session-timeout> <cookie-config><name>JSESSIONID</name></cookie-config> </session-config> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:spring_context.xml ,classpath:quartz_context.xml ,classpath:spring_context_misc.xml ,classpath:bpms_context.xml, classpath:process_group.xml </param-value> </context-param> <listener> <listener-class>cn.ccccltd.waf.listener.SessionListener</listener-class> </listener> <listener> <listener-class>cn.ccccltd.waf.listener.CacheFileEvent</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.apache.commons.fileupload.servlet.FileCleanerCleanup</listener-class> </listener> <listener> <listener-class>cn.ccccltd.bpms.BpmsInitializer</listener-class> </listener> <listener> <listener-class>cn.ccccltd.bpms.ou.listener.BpmsSessionListener</listener-class> </listener> <filter> <filter-name>SigninFilter</filter-name> <filter-class>cn.ccccltd.waf.SigninFilter</filter-class> <init-param> <param-name>signinUrlPattern</param-name> <param-value>bo,dhtml,dhtm,shtml,shtm</param-value> </init-param> </filter> <filter-mapping> <filter-name>SigninFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- ****************************************************************************** --> <filter> <filter-name>xssFilter</filter-name> <filter-class>cn.ccccltd.waf.filter.XssFilter</filter-class> </filter> <filter-mapping> <filter-name>xssFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>SSOLoginFilter</filter-name> <filter-class>cn.ccccltd.waf.sso.controller.SSORequestController</filter-class> </filter> <filter-mapping> <filter-name>SSOLoginFilter</filter-name> <url-pattern>*.bo</url-pattern> </filter-mapping> <!--<filter> <filter-name>springSessionRepositoryFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSessionRepositoryFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>ERROR</dispatcher> </filter-mapping>--> <servlet> <servlet-name>appDispatcher</servlet-name> <servlet-class>cn.ccccltd.waf.AppDispatcher</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring_dispatcher_context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- Spring MVC 请求映射 --> <servlet-mapping> <servlet-name>appDispatcher</servlet-name> <url-pattern>*.bo</url-pattern> </servlet-mapping> <servlet> <servlet-name>appLoader</servlet-name> <servlet-class>cn.ccccltd.waf.AppLoader</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet> <servlet-name>monitorLoader</servlet-name> <servlet-class>cn.ccccltd.waf.MonitorLoader</servlet-class> <load-on-startup>30</load-on-startup> </servlet> <servlet> <servlet-name>fileUpload</servlet-name> <servlet-class>cn.ccccltd.waf.tool.FileUpload</servlet-class> <load-on-startup>97</load-on-startup> </servlet> <servlet> <servlet-name>randomCode</servlet-name> <servlet-class>cn.ccccltd.waf.tool.RandomCode</servlet-class> <load-on-startup>99</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appDispatcher</servlet-name> <url-pattern>*.dhtml</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>appDispatcher</servlet-name> <url-pattern>*.dhtm</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>appDispatcher</servlet-name> <url-pattern>*.shtml</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>appDispatcher</servlet-name> <url-pattern>*.shtm</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>fileUpload</servlet-name> <url-pattern>/waf/tool/fileUpload</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>randomCode</servlet-name> <url-pattern>/waf/tool/randomCode</url-pattern> </servlet-mapping> <servlet> <servlet-name>FileUploadServlet</servlet-name> <servlet-class>cn.ccccltd.comm.upload.FileUploadServlet</servlet-class> <init-param> <param-name>fileSizeLimit</param-name> <param-value>2000</param-value> </init-param> </servlet> <servlet> <servlet-name>DeleteFileServlet</servlet-name> <servlet-class>cn.ccccltd.comm.upload.DeleteFileServlet</servlet-class> </servlet> <servlet> <servlet-name>FileDownloadServlet</servlet-name> <servlet-class>cn.ccccltd.comm.upload.FileDownloadServlet</servlet-class> </servlet> <!-- 帆软报表 --> <!-- <servlet> <servlet-name>ReportServer</servlet-name> <servlet-class>com.fr.web.ReportServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>ReportServer</servlet-name> <url-pattern>/ReportServer</url-pattern> </servlet-mapping> --> <servlet-mapping> <servlet-name>FileDownloadServlet</servlet-name> <url-pattern>/FileDownloadServlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>FileUploadServlet</servlet-name> <url-pattern>/FileUploadServlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>DeleteFileServlet</servlet-name> <url-pattern>/DeleteFileServlet</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- error-page START --> <!-- 400 --> <error-page> <error-code>400</error-code> <location>/errorPage.jsp</location> </error-page> <!-- 403 --> <error-page> <error-code>403</error-code> <location>/errorPage.jsp</location> </error-page> <!-- 404 --> <error-page> <error-code>404</error-code> <location>/errorPage.jsp</location> </error-page> <!-- 500 --> <error-page> <error-code>500</error-code> <location>/errorPage.jsp</location> </error-page> <!-- error-page END --> </web-app>那你给我修改一下文件都在项目之中。
06-11
<?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_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>agileEx</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>CharacterEncodingFilter</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> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>agileEx</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/springMvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>agileEx</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <filter> <display-name>PpmFilter</display-name> <filter-name>PpmFilter</filter-name> <filter-class>com.dahuatech.core.interceptor.PpmFilter</filter-class> </filter> <filter-mapping> <filter-name>PpmFilter</filter-name> <url-pattern>/property/*</url-pattern> </filter-mapping> <filter> <display-name>TpmFilter</display-name> <filter-name>TpmFilter</filter-name> <filter-class>com.dahuatech.core.interceptor.TpmFilter</filter-class> </filter> <filter-mapping> <filter-name>TpmFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <display-name>dimission</display-name> <filter-name>dimission</filter-name> <filter-class>com.dahuatech.core.interceptor.DimissionFilter</filter-class> </filter> <filter-mapping> <filter-name>dimission</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <display-name>RestAuthFilter</display-name> <filter-name>RestAuthFilter</filter-name> <filter-class>com.dahuatech.core.interceptor.RestAuthFilter</filter-class> </filter> <filter-mapping> <filter-name>RestAuthFilter</filter-name> <url-pattern>/rest/*</url-pattern> </filter-mapping> </web-app>
最新发布
11-15
<?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" version="3.0"> <display-name></display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:applicationContext*.xml classpath*:*Context.xml </param-value> </context-param> <context-param> <param-name>webAppRootKey</param-name> <param-value>rms.root</param-value> </context-param> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/classes/log4j.properties</param-value> </context-param> <context-param> <param-name>log4jRefreshInterval</param-name> <param-value>60</param-value> </context-param> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>com.hg.filter.UrlAuthListen</listener-class> </listener> <listener> <listener-class>com.hg.filter.WebConfigListener</listener-class> </listener> <filter> <filter-name>openSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter </filter-class> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>openSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <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> <filter> <filter-name>XssFilter</filter-name> <filter-class>com.hg.aop.XssFilter</filter-class> </filter> <filter-mapping> <filter-name>XssFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- dwr 配置 --> <servlet> <servlet-name>dwr-invoker</servlet-name> <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>activeReverseAjaxEnabled</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>crossDomainSessionSecurity</param-name> <param-value>false</param-value> </init-param> <init-param> <description>How quickly do scriptSessions timeout?</description> <param-name>scriptSessionTimeout</param-name> <param-value>1800000</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping> <listener> <listener-class>org.directwebremoting.servlet.EfficientShutdownServletContextAttributeListener</listener-class> </listener> <!-- dwr 配置 --> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>具体解释一下web.xml的配置
07-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值