web.xml中配置spring监听,日志记录,编码集等,spring的mvc
2014-01-13 22:30
555 查看
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext-*.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
contextConfigLocation指定了配置文件的路径。如果不配置默认的路径是在WEB-INFO下面。通配符可以加载所有匹配的文件
ContextLoaderListener监听器的作用在web容器启动时候可以加载applicationContext的相关配置信息,他实现了ServletContextListener接口。在
web容器启动的时候就可以执行他实现的方法。ContextLoaderListener implements ContextServletListener实现它里面的contextInitialized方法
public void contextInitialized (ServletContextEvent event) {
this.contextLoader = createContextLoader();
this.contextLoader.initWebApplicationContext(event.getServletContext());
public ContextLoader createContextLoader(){
return new ContextLoader():
}
}此方法里面通过contextLoader对象初始化web应用。此方法是spring容器的启动入口
配置web应用的编码集
<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> 过滤器的匹配 URL
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
还可以配置日志文件
设置日志的跟踪:
① 指定 Log4J 配置文件的地址
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
…
② 使用该监听器初始化 Log4J 日志引擎
<listener>
<listener-class> org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext-*.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
contextConfigLocation指定了配置文件的路径。如果不配置默认的路径是在WEB-INFO下面。通配符可以加载所有匹配的文件
ContextLoaderListener监听器的作用在web容器启动时候可以加载applicationContext的相关配置信息,他实现了ServletContextListener接口。在
web容器启动的时候就可以执行他实现的方法。ContextLoaderListener implements ContextServletListener实现它里面的contextInitialized方法
public void contextInitialized (ServletContextEvent event) {
this.contextLoader = createContextLoader();
this.contextLoader.initWebApplicationContext(event.getServletContext());
public ContextLoader createContextLoader(){
return new ContextLoader():
}
}此方法里面通过contextLoader对象初始化web应用。此方法是spring容器的启动入口
配置web应用的编码集
<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> 过滤器的匹配 URL
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
还可以配置日志文件
设置日志的跟踪:
① 指定 Log4J 配置文件的地址
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
…
② 使用该监听器初始化 Log4J 日志引擎
<listener>
<listener-class> org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
相关文章推荐
- SpringMVC Interceptor 配置由简单到复杂及相关异常解决办法,记录用户操作日志
- springmvc+spring的web.xml配置
- spring-mvc注解web.xml配置问题
- SpringMVC+Spring+MyBatis 的综合练习 4 (配置 web.xml )
- java注解方式(不用xml)配置web框架spring+SpringMVC
- web.xml 中spring-mvc.xml 和 spring-application.xml 配置位置及含义
- web.xml中spring/springmvc配置详解
- spring与struts2 mvc共存web.xml简单配置
- SpringMVC+Hibernate+jQuery+js+css+jsp+nginx整合时,(1)jsp引入js,css无效;(2)插入数据库时某字段为空;(3)web.xml配置完后,从数据库读数
- Spring MVC +Mybatis + Maven 配置之web.xml配置
- SpringMVC(1):基础配置文件web.xml 和 <servlet-name>-servlet.xml / springmvc.xml
- 关于搭建restful web service + springMVC + ibatis/hibernate的整合和XML配置意思和ssh+springMVC框架搭建
- spring与struts2 mvc共存web.xml简单配置
- Unit03: Spring Web MVC简介 、 基于XML配置的MVC应用 、 基于注解配置的MVC应用
- springmvc+shiro简单配置及作用(WEB.XML springmvc部分)
- Spring Web MVC简介 、基于XML配置的MVC应用 、基于注解配置的MVC应用
- web.xml+spring mvc基本配置
- 配置pom.xml、spring.xml、spring-mvc.xml、spring-mybatis.xml、web.xml
- 在web.xml中配置,使用配置类替代springmvc.xml和applicationContext.xml
- SPRINGMYBATIS01 Unit03: Spring Web MVC简介 、 基于XML配置的MVC应用 、 基于注解配置的MVC应用