页面设置的是utf-8,汉字在页面上可以正常显示,但是通过 *.action给action传汉字,到action的时候就是乱码了。在action中已经写了request.setcharacterEncoding(utf-8);response.setContentType("text/html");
但是还是乱码啊。请高手解答,先谢谢了。

解决方案 »

  1.   

    在action中已经写了request.setcharacterEncoding(utf-8);response.setContentType("text/html");
    这个检查没有效果?检查是否在
    request.setcharacterEncoding(utf-8);
    调用了request.getParameter,检查 拦截器是否工作正常
      

  2.   

    我以前也遇到了这个问题,解决方法如下:
    1.自定义一个类继承ActionServlet,重写
    protected void process(HttpServletRequest request,
    HttpServletResponse response) throws IOException, ServletException { }方法,并且加上这句话
    request.setCharacterEncoding("utf-8");2.修改web.xml文件,将struts自带的
    <servlet>  
        <servlet-name>action</servlet-name>
        <servlet-class>com.fendou.vo.ABC</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>2</param-value>
        </init-param>
        <init-param>  
          <param-name>detail</param-name>
          <param-value>2</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
      </servlet>中的<servlet-class>里面的类改为你刚刚写的类
      

  3.   

    一般页面给action传值,用submit提交页面,经过struts的过滤应该没问题,
    你重写url的话一般会乱码前几天我也遇到这个问题,不过我传给action的是message,不在action用。redirect后在页面提示消息,
    我先是encodeURI(msg),然后在页面里面decodeURI(msg),就不乱码但是你要是在action里用的我也不知道该怎么办,最好还是用提交的方式吧,把form的action改成你要转向
    的action,然后再改回来,应该就没问题了
      

  4.   

    <form method="post">应该就不会有乱码问题。
    如果是get还是会有乱码问题
      

  5.   

    response.setContentType("text/html");改成:response.setContentType("text/html;charset=utf-8");