在web.xml文件中加入Spring的utf-8过滤器

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"

  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"

  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

  <filter>

    //过滤器使用spring类CharacterEncodingFilter

             <filter-name>encodingFilter</filter-name>

             <filter-class>

                        org.springframework.web.filter.CharacterEncodingFilter

             </filter-class>

             <init-param>

                        <param-name>encoding</param-name>

    //过滤器过滤后的编码为utf-8

                        <param-value>utf-8</param-value>

             </init-param>

  </filter>

  <filter-mapping>

    //过滤所有的路径:/*代表所有的路径

             <filter-name>encodingFilter</filter-name>

             <url-pattern>/*</url-pattern>

  </filter-mapping>

  <servlet>

             <servlet-name>action</servlet-name>

    //struts中的ActionServlet,所有的请求应答由ActionServlet来处理

             <servlet-class>

                        org.apache.struts.action.ActionServlet

             </servlet-class>

             <init-param>

    //struts中的配置文件的存放位置

                        <param-name>config</param-name>

                        <param-value>/WEB-INF/struts-config.xml</param-value>

             </init-param>

             <init-param>

                        <param-name>debug</param-name>

                        <param-value>3</param-value>

             </init-param>

             <init-param>

                        <param-name>detail</param-name>

                        <param-value>3</param-value>

             </init-param>

             <load-on-startup>0</load-on-startup>

  </servlet>

  <servlet-mapping>

    //映射的后缀扩展名名称

             <servlet-name>action</servlet-name>

             <url-pattern>*.do</url-pattern>

  </servlet-mapping>

  <welcome-file-list>

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

  </welcome-file-list>

</web-app>

类org.springframework.web.filter.CharacterEncodingFilter是Spring特有的,专门解决Web的中文utf-8乱码问题。

posted @ 2010-10-29 14:22  留心_frankliujava  阅读(3744)  评论(0编辑  收藏  举报