<form action="getMReader.action" method="get">
                        <table class="tbAddContactinfo" width="100%">
                            <tr>
                                <td style=" width:100px; text-align:right;">
                                    <span>读者名:</span>
                                </td>
                               
                                <td>
                                    <input id="Text2" type="text" name="name" style="width:300px;" />
                                </td>
                                <td style="width:100px;">
                                    <input type="submit" value="查询"/>
                                </td>
                                <td style="width:100px;">
                                    <input type="button" value="添加" onclick="add();"/>
                                </td>
                                <td style="width:50%;"></td>
                                </tr>
                        </table>
                        </form>
求大神,回复尽量清楚详细一点,本人新手乱码

解决方案 »

  1.   

    把页面和action的字符全部设置为常用的utf-8,或者创建一个字符过滤器
      

  2.   

    jsp文件上加:
    <%@ page contentType="text/html;charset=UTF-8"%>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">然后java文件的编码格式也调为UTF-8
      

  3.   

    String name=new String(name.getBytes("iso8859-1"),"gb2312");
      

  4.   

    在web.xml配置<filter>
            <filter-name>struts-cleanup</filter-name>
            <filter-class>
                org.apache.struts2.dispatcher.ActionContextCleanUp
            </filter-class>       
        </filter>
       
        <filter-mapping>
            <filter-name>struts-cleanup</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
      

  5.   

    在web.xml配置<filter>
            <filter-name>struts-cleanup</filter-name>
            <filter-class>
                org.apache.struts2.dispatcher.ActionContextCleanUp
            </filter-class>       
        </filter>
       
        <filter-mapping>
            <filter-name>struts-cleanup</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

    <form action="getMReader.action" method="post"></form>
      

  6.   

    最简单有效form action="getMReader.action" method="post"
      

  7.   

    如果你是get方法,要解决乱码问题,你得通过:String(name.getBytes("iso8859-1"),"gb2312")
    或者在config/Server.xml中找到Connector这个元素,然后,在这个元素中一个属性:URIEncoding="GBK"
    这样可以统一解决。