4、容器创建<listener>中的类实例,创建监听器。
web.xml中配置执行顺序ServletContext-> context-param ->listener -> filter -> servlet
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:/spring/spring-content.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener> <!--log4j配置文件加载--> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:setup/log4j.xml</param-value> </context-param> <!--启动Log4jConfigListener监听器 每60s监听一次log4j.xml配置文件的变化--> <context-param> <param-name>log4jRefreshInterval</param-name> <param-value>60000</param-value> </context-param> <listener> <listener-class> org.springframework.web.util.Log4jConfigListener </listener-class> </listener> <!--log4j.properites加载Log4j --> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:log/console.properties</param-value> </context-param> <context-param> <param-name>log4jRefreshInterval</param-name> <!--Spring默认刷新Log4j配置文件的间隔,单位为millisecond --> <param-value>60000</param-value> </context-param> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <!-- logback配置 --> <context-param> <param-name>logbackConfigLocation</param-name> <param-value>classpath:logback.xml</param-value> </context-param> <listener> <listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class> </listener> <!--启动应用程序初始化监听器 ApplicationInitListener--> <listener> <listener-class>com.rrtong.frame.ApplicationInitListener</listener-class> </listener> <!-- Spring MVC 相关配置 --> <servlet> <servlet-name>Dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:setup/applicationContext-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- 防止spring内存溢出监听器 --> <listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </listener> <servlet-mapping> <servlet-name>Dispatcher</servlet-name> <url-pattern>*.do</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>*.do</url-pattern> </filter-mapping> <!-- 定义默认页面 --> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- 自定义jstl标签函数 --> <jsp-config> <taglib> <taglib-uri>http://tags.rrtong.com/pj</taglib-uri> <taglib-location>/WEB-INF/jstl/custom.tld</taglib-location> </taglib> <taglib> <taglib-uri>http://java.sun.com/jsp/jstl/rrtong</taglib-uri> <taglib-location>/WEB-INF/jstl/unescape.tld</taglib-location> </taglib> </jsp-config> <!--定义验证码--> <servlet> <servlet-name>Kaptcha</servlet-name> <servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Kaptcha</servlet-name> <url-pattern>/kaptcha.jpg</url-pattern> </servlet-mapping> <!-- 加载dwr --> <servlet> <servlet-name>dwr-invoker</servlet-name> <servlet-class>org.directwebremoting.spring.DwrSpringServlet</servlet-class> <init-param> <!-- dwr测试页面,上线时设置为false --> <param-name>debug</param-name> <param-value>true</param-value> </init-param> <!-- dwr拦截 --> <init-param> <param-name>org.directwebremoting.extend.Remoter</param-name> <param-value>com.pinhuba.web.filter.dwrRemoter.DWRRemoter</param-value> </init-param> <init-param> <!-- 防止其他域提交访问 --> <param-name>crossDomainSessionSecurity</param-name> <param-value>false</param-value> </init-param> <!-- 压缩js --> <init-param> <param-name>scriptCompressed</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- 定义session过期时间 --> <session-config> <session-timeout>30</session-timeout> </session-config> <!-- 配置自定义错误页面 --> <error-page> <error-code>404</error-code> <location>/error/404.html</location> </error-page> <error-page> <error-code>500</error-code> <location>/error/500.html</location> </error-page> <!--tomcat集群配置--> <display-name>rrtong</display-name> <distributable/>
如果通过java读取param-value,getServletContext().getInitParameter("my_param")方式可以读取到数据。
<context-param> <param-name>my_param</param-name> <param-value>hello</param-value> </context-param>