页面统一使用中文编码UTF-8
一、页面显示中文乱码的解决办法
JSP页面中加入以下代码
    
<%@ page pageEncoding="UTF-8" %>
二、传递参数为中文乱码
1、修改容器的server.xml文件,解决连接方式和Get方式乱码问题
 
<Connector port="8001" protocol="HTTP/1.1" maxThreads="150"
  connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />

2、编写过滤器
 
编写过滤器类文件
 
 
package com.meixin.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

//编写过滤器,需要实现javax.servlet.Filter接口
public class CharactorEncodingFilter implements Filter
{
  public void destroy()
  {
  }
  //在doFilter方法中处理
  public void doFilter(ServletRequest request, ServletResponse response,
      FilterChain chain) throws IOException, ServletException
  {
    //将所有request内的对象设置字符集为UTF-8
    request.setCharacterEncoding("UTF-8");
    //用chain的doFilter处理过滤
    chain.doFilter(request, response);
  }
  public void init(FilterConfig arg0) throws ServletException
  {
  }
}
web.xml文件中配置过滤器
<?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     [url]http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd[/url]">

  <!-- 在web.xml文件中增加对Filter的设置 -->
  <filter>
    <!-- filter的名称 -->
    <filter-name>charactorEncoding</filter-name>
    <!-- filter对应的类 -->
    <filter-class>
      com.meixin.filter.CharactorEncodingFilter
    </filter-class>
  </filter>
  <!-- 设置过滤器调用的映射 -->
  <filter-mapping>
    <!-- filter的名称,和设置中的名称要一致 -->
    <filter-name>charactorEncoding</filter-name>
    <!-- 设置对当前的request,response请求都进行过滤 -->
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>
      org.apache.struts.action.ActionServlet
    </servlet-class>
    <init-param>
      <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>
要使配置生效,必须重启web服务器。