我用
package util;
import java.io.IOException;import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.RequestProcessor;public class EncodingProcessor extends RequestProcessor {// @Override
 public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  // TODO 自动生成方法存根
  request.setCharacterEncoding("GB2312");
  super.process(request, response);
 }}
在 struts-config.xml  
<struts-config>中 加入   
      <controller   processorClass="   你的RequestProcessor处理器类名"   />   
怎么会报错了用了Filter类还是不能解决求高手帮忙!!! 

解决方案 »

  1.   

    这位LZ,你的username数据从哪里来:数据库还是页面表单?
    从页面来应该不会乱码,因为有:request.setCharacterEncoding("GB2312");~
    我猜想是从数据库来,得设置数据库得字符集~
      

  2.   

    在web.xml文件里面加上如下配置试试
       <!--添加过滤器,解决表单提交时的中文乱码问题-->
        <filter>
            <filter-name>SetCharacterEncoding</filter-name>
            <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>gb2312</param-value>
            </init-param>
        </filter>    <!-- 要过滤的类型 -->
        <filter-mapping>
            <filter-name>SetCharacterEncoding</filter-name>
            <url-pattern>*.jsp</url-pattern>
        </filter-mapping>
        <filter-mapping>
            <filter-name>SetCharacterEncoding</filter-name>
            <url-pattern>*.do</url-pattern>
        </filter-mapping>
        <filter-mapping>
            <filter-name>SetCharacterEncoding</filter-name>
            <url-pattern>*.htm</url-pattern>
        </filter-mapping>
        <filter-mapping>
            <filter-name>SetCharacterEncoding</filter-name>
            <url-pattern>*.html</url-pattern>
        </filter-mapping>