写错应该这样:
response.setCharacterEncoding("GBK");
但还是不行,是乱码

解决方案 »

  1.   

    tomcat5.0. 的版本 setCharacterEncoding 方法只能对 post 传入的值进行转码。对GET请求的值不能转码。我也不知道为什么。
    对GET的值,建议用 getBytes()方法进行转。我现在,在tomcat中以不使用setCharacterEncoding 了
      

  2.   

    index.jsp
    <html>
    <head>
    </head>
    <body>
    <form method="POST" name="form1" action="test.jsp" >
    <input type="input" name="sName" value="这是汉字"> 
    <input type="submit" value="submit">
    </form>
    </body>
    </html>test.jsp<%@ page contentType="text/html;charset=GBK" language="java" %>
    <%@ page import="com.sailing.util.*"%>
    <%
    //request.setCharacterEncoding("GBK");
    UtRequest utRequest = new UtRequest(request);
    String sGbk = utRequest.getString("sName");
    String sIso = new String(sGbk.getBytes("ISO-8859-1"),"GBK");
    %>ISO:<%=sGbk%><br>
    GBK:<%=sIso%><br>
      

  3.   

    UtRequest utRequest  是对转码的一个封装,我同在,所有页面。用我自己封装的request
      

  4.   

    对于地址中的中文参数转码好象也是不行的,
    改成下面的就可以了Input.jsp
    -------------------
    <%@page contentType="text/html; charset=GBK"%>
    <%!
        public String ConvertStr(String sStr) {
            String sRtn = "";
            if (sStr == null) {
                sRtn = "";
            } else {
                try
                {
                    sRtn = new String(sStr.getBytes("ISO-8859-1"), "GBK");
                }
                catch(Exception ex)
                {
                    sRtn="";
                }
            }
            return sRtn;
        }
     %>
    <html>
    <script language="javascript">
    <!--function window_Onload()
    {
        window.focus();    <%
        //String sTitle1=ConvertStr(request.getParameter("Title1"));
          String sTitle1=java.net.URLDecoder.decode(request.getParameter("Title1"));
        %>
        PromptText.innerText="<%=sTitle1%>";
    }
    -->
    </script>
    <body onload="window_Onload()">
    <P id=PromptText></P>
    </body>
    </html>
    你那个转码的方法其实根本没用到,因为是没有效果的---------------------
    servlet
    ------------------------------
    res.setContentType("text/html;charset=gb2312");
    String str=java.net.URLEncoder.encode("请输入");
    res.sendRedirect("Input.jsp?Title1=" + str);