`

在web.xml中配置spring同时设置字符编码过滤器

阅读更多
<?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"
	version="2.5">

	<display-name>chihiro Application Server</display-name>

	<context-param>
		<param-name>logbackConfigLocation</param-name>
		<param-value>/WEB-INF/logback.xml</param-value>
	</context-param>

	<listener>
		<listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class>
	</listener>

	<!-- Spring -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/common/spring-beans.xml</param-value>
	</context-param>

	<servlet>
		<servlet-name>chihiro</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>/WEB-INF/common/controller.xml</param-value>
		</init-param>
		<load-on-startup>2</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>chihiro</servlet-name>
		<url-pattern>*.htm</url-pattern>
	</servlet-mapping>

	<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>*.htm</url-pattern>
	</filter-mapping>

	<welcome-file-list>
		<welcome-file>/index.jsp</welcome-file>
	</welcome-file-list>

	<error-page>
		<error-code>404</error-code>
		<location>/error.html</location>
	</error-page>
	<error-page>
		<error-code>500</error-code>
		<location>/error.html</location>
	</error-page>

</web-app>

     监听器首先检查contextConfigLocation 参数,如果它不存在,它将使用/WEB-INF/applicationContext.xml 作为默认值。

   ContextLoaderServlet 同ContextLoaderListener 一样使用contextConfigLocation 参数。

分享到:
评论

相关推荐

    spring+shiro+ehcache例子

    在web.xml中配置字符过滤器 5:项目运行信息查看 在web.xml中配置log4j信息打印 (需要自己将log4j的配置文件给打开) 三: 配置文件 查看/src/config/ ,配置文件可观察文件名称理解 四: 登录名为2:可以...

    spring3.1中文参考文档

    spring3.1中文参考文档,南磊翻译,现在有4章,目录如下: 第一部分 Spring framework概述.......................................................................................................................

    spring2.5 struts2.0 hibernate3.2.5 搭建的企业级开发基础模块

    字符集过滤器:com.light.framework.filter 项目字符集请用UTF-8 com.light.framework包中还有些小东西 自己看看吧 我是用MyEclipse6.0开发的(MyEclipse7.0M2导入也没问题) 希望大家用其他版本时不会出现...

    ssh(structs,spring,hibernate)框架中的上传下载

     由于Spring通过代理Hibernate完成数据层的操作,所以原Hibernate的配置文件hibernate.cfg.xml的信息也转移到Spring的配置文件中:  代码 4 Spring中有关Hibernate的配置信息 1. 2. !-- 数据源的配置 //--> 3. ...

    Spring 3 Reference中文

    4.6.1.6 在非Web 应用中,优雅地关闭Spring IoC 容器 74 4.6.2 ApplicationContextAware 和BeanNameAware . 75 4.6.3 其它Aware 接口 75 4.7 Bean 定义的继承. 77 4.8 容器扩展点. 78 4.8.1...

    Java Web编程宝典-十年典藏版.pdf.part2(共2个)

    5.4.5 实现字符编码过滤器 5.5 实战检验 5.5.1 通过Servlet实现录入用户信息 5.5.2 应用过滤器实现网页计数器 5.6 疑难解惑 5.6.1 访问Servlet出现404错误 5.6.2 修改Servlet无效 5.6.3 创建过滤器并没有实现过滤...

    spring-cloud:springCloud学习笔记

    maven父子项目父工程配置新项目,maven,父工程名称字符编码,设置,编辑器文件编码注解功效激活java编译选择1.8 文件类型文件过滤删除掉父工程下的src,只保留一个pom.xml父工程的pom.xml包装设置为绒球maven中的...

    基于MyEclipse搭建maven+springmvc整合图文教程(含源码0

    -- 字符集 过滤器 --&gt; &lt;filter-name&gt;CharacterEncodingFilter &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter &lt;param-name&gt;encoding &lt;param-value&gt;UTF-8 ...

    JBoss Seam 工作原理、seam和hibernate的范例、RESTFul的seam、seam-gen起步、seam组件、配置组件、jsf,jboss、标签、PDF、注解等等

    1.3. Seam 中的可点击列表:消息示例............................................................................................................................. 27 1.3.1. 理解代码.........................

    数据库乱码的小技巧

    老是出现中文乱码,根据网上的各种策略,使用spring自带的字符过滤器啊,设置页面编码啊,设置数据库编码啊都设置好为UTF-8了,还是出现中问乱码,后来在spring的配置文件applicationContext.xml中的配置数据源中的...

    Grails 中文参考手册

    11.2 字符串的编码和解码 11.3 身份验证 11.4 关于安全的插件 11.4.1 Acegi 11.4.2 JSecurity 12 插件 12.1 创建和安装插件 12.2 理解插件的结构 12.3 提供基础的工件 12.4 评估规约 12.5 参与构建事件 12.6 参与...

    Nginx安装包

    最后我们还需要在web.xml中加入spring的session过滤器,我个人理解这个过滤器的作用是告诉spring来接管对session管理与创建工作。 1 &lt;!--session过滤器--&gt; 2 3 &lt;filter-name&gt;springSessionRepositoryFilter 4 ...

    Java EE常用框架.xmind

    在Shiro配置文件上配置在web.xml对应的bean 配置安全管理器 配置自定义的realm Shiro过滤器 anon:例子/admins/**=anon 没有参数,表示可以匿名使用。 authc:例如/admins/user/**=authc表示需要...

    乐优商城.xmind

    通过 @PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中:URL 中的 {xxx} 占位符可以通过@PathVariable(“xxx“) 绑定到操作方法的入参中。 select * from tb_category where id in (select ...

    java基础题 很全面

    2. 我们在web应用开发过程中经常遇到输出某种编码的字符,如iso8859-1等,如何输出一个某种编码的字符串? 30 3. 请问输出什么,为什么? 30 4. 编程题: 写一个Singleton出来。 31 5. 设计4个线程,其中两个线程每次对j...

    Java学习笔记-个人整理的

    {2.8}框架中移动的小球}{59}{section.2.8} {2.9}抽象与接口}{59}{section.2.9} {2.10}访问控制}{60}{section.2.10} {2.10.1}类的属性}{60}{subsection.2.10.1} {2.10.2}类的方法}{61}{subsection.2.10.2} {...

    freemarker总结

    节点变量表示为树型结构中的一个节点,通常在XML处理中使用。 在模板里对sequences和hashes初始化 sequences 1. [“you”,”me”,”he”] 2. 1..100 3. [ {“Akey”:”Avalue”},{“Akey1”:”Avalue1”}, {“B...

    java开源包101

    JCaptcha4Struts2 是一个 Struts2的插件,用来增加验证码的支持,使用时只需要用一个 JSP 标签 (&lt;jcaptcha:image label="Type the text "/&gt; ) 即可,直接在 struts.xml 中进行配置,使用强大的 JCaptcha来生成验证码...

Global site tag (gtag.js) - Google Analytics