request.setCharacterEncoding(“GBK”)

解决方案 »

  1.   

    strName = new String(request.getParameter("name").getBytes("ISO-8859-1"));
      

  2.   

    Filter最好,但要注意配置
    在接受端采用
    strName = new String(request.getParameter("name").getBytes("ISO-8859-1"),"gb2312");也可以
      

  3.   

    request.setCharacterEncoding(“GBK”)和
    strName = new String(request.getParameter("name").getBytes("ISO-8859-1"));
    都预报
    Incompatible type for constructor. Can't convert java.lang.String to byte[].
    这是什么错误?
      

  4.   

    strName = new String(request.getParameter("name").getBytes("ISO-8859-1"));
    或加入函数试试public static String getStr(String str) 
      {
          try{
             String temp_p=str;
             byte[] temp_t=temp_p.getBytes("ISO8859_1");
             String temp=new String(temp_t);
             return temp;
            }
            catch(Exception e)
            {
                System.out.println(e.toString());
                return "null";
            }
          
      }
      

  5.   

    不好意思,我是初学者,问一下,Filter是什么啊?谢谢
      

  6.   

    <a href="./test1.jsp?name=<%= name%>">
    如果name变量是中文,就不能传递过去,查了很多资料都不能解决
    大家都是怎么解决的啊?郁闷死了!我快疯了啊
      

  7.   

    <%!
    public static String getStr(String str) 
      {
          try{
             String temp_p=str;
             byte[] temp_t=temp_p.getBytes("ISO8859_1");
             String temp=new String(temp_t);
             return temp;
            }
            catch(Exception e)
            {
                System.out.println(e.toString());
                return "null";
            }
          
      }
    %>
    <%String aa =getStr(request.getParameter("name"));%>
      

  8.   

    比如: 
    pnr="中文"; 
    URL url=new URL( "http://202.106.139.30:80/servlet/zm_booktkt.SeePnr?pnrno="+URLEncoder.encode(pnr) );
      

  9.   

    在接受端:
    strName = new String((request.getParameter("name")).getBytes("ISO-8859-1"),"gb2312");
    一定要注意括号(request.getParameter("name"))是不可缺少的!
      

  10.   

    在test1.jsp页面的开头加上
    <%
      request.setCharacterEncoding("gb2312");  //正常接收中文
    %>
      

  11.   

    to:poyer(瑞德) 
    出现如下错误:
    Unable to compile class for JSP/usr/local/jakarta-tomcat/work/localhost_8080/_0002ftest_00031_0002ejsptest1_jsp_16.java:57: Method setCharacterEncoding(java.lang.String) not found in interface javax.servlet.http.HttpServletRequest.
                    request.setCharacterEncoding("gb2312");
      

  12.   

    写一个简单的JavaBean,以后调用也方便!
    package beans ;
    public class  ISOtoGB2312
    {
    public  String getConvert(String str) 
    {
    try
    {
    byte[] byteStr=str.getBytes("ISO-8859-1");
    return new String(byteStr,"gb2312");
    }
    catch(Exception e)
    {
    return str;
    }
        }
    }
    <jsp:useBean id="chage" scope="session" class="beans.ISOtoGB2312"/>String newname=chage.getConvert(request.getParameter("newname"));这样就可以!
      

  13.   

    jiaminxy(烟草味道) 正解只需要将传递的字符串URLEncode一下就行了。Encode之后成为类似于%2F%2D等的字符,到了另一个叶面Decode回来就行了。
    对于用Form POST方式提交的表单,不需要这个步骤;对于用直接写xxx.jsp?name=YYY的,需要这样做。
      

  14.   

    在接受变量的页面
    String strValue = request.getParameter("valueName");
    strValue = new String(strValue.getBytes("ISO8859_1"),"gb2312");
      

  15.   

    <%
    String newStr=new String(request.getParameter("name").getBytes("ISO-8859-1"));
    %>
      

  16.   

    <%
         String test="中文";
         String name2=java.net.URLEncoder.encode(test);
         String name3=java.net.URLDecoder.decode(name2);     out.print(name3);
        %>
    显示结果还是??的乱码,怎么回事,还是没有解决啊?
    我快疯了啊!
      

  17.   

    String name=new String(request.getParameter("name").getBytes("ISO-8859-1"));
      

  18.   

    在<head></head>里加上
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    就ok了!
      

  19.   

    在文件顶端加上如下的代码:然后就可以直接取得参数名为中文的对应参数值。
    <%request.setCharacterEncoding("gb2312");%>
    比如你要传递的参数名是“中文”,参数值是“姓名”
    <%String name=request.getParameter("中文");%>
    则<%=name%>的输出结果就是“姓名”了
      

  20.   

    发送端:
       strName = new String((request.getParameter("name")).getBytes("gb2312"),"ISO-8859-1");
    接受端:
       jsp头部加<%@ page contentType="text/html;charset=gb2312"%>
       或jsp程序内部加
       String title = null;
         while(rs.next()){
               title = rs.getString("title");
               title =  new String(title.getBytes("GBK"), "ISO8859_1");
     %>
      

  21.   

    如果还不行,
    如果你是用tomcat的话,你升级到tomcat4.1版本的
    我以前就遇到这种问题,其它的方法都试过后
    升级tomcat到tomcat4.1版本就解决了