大家帮帮忙啊,我通过getParameter取得的中文参数怎么是乱码啊?下面是我的两个页面的代码,请热心人给我看看,谢谢
<%@ page contentType="text/html;chatset=gb2312"%>
<center>
<h1>留言管理</h1><hr><br>
<form action="insert_do.jsp" method="post">
<table>
   <tr><td colspan="3">添加新留言</td></tr>
   <tr><td>标题:</td><td><input type="text" name="title"></td></tr>
   <tr><td>作者:</td><td><input type="text" name="author"></td></tr>
   <tr><td>内容:</td><td><textarea name="content" cols="30"rows="6"></textarea></td></tr>
   <tr><td colspan="2">
      <input type="submit" value="添加">
      <input type="reset" value="重置"></td></tr>
</table>
</form>
</center>
<%@ page contentType="text/html;charset=gb2312"%>
<% request.setCharacterEncoding("gb2312"); %>
<html>
<meta http-equiv="Content-Type"content="text/html;charset=gb2312">
<body>
<center>
    <% content=new String(request.getParameter("content").getBytes("8859_1"));%>
    <%=request.getParameter("content")%>
</center>
</body>
</html>

解决方案 »

  1.   

    我觉得是这样的
    <% content=new String(request.getParameter("content").getBytes("8859_1"),"gb2312");%>
    new String(string.getBytes("解码字符集"),"解码字符集")
    getBytes(String charsetName) 
              使用指定的字符集将此 String 解码为字节序列,并将结果存储到一个新的字节数组中。
    String(byte[] bytes, String charsetName) 
              构造一个新的 String,方法是使用指定的字符集解码指定的字节数组。
    API是好东西啊,我也是新手,不知对不对,清高收指点了!
      

  2.   


    public String parseChinese(String in){
    String s=null;
    byte temp[];
    if(in==null){
    System.out.println("Warn:Chinese null founded!");
    return new String("");
    }
    try{
    temp=in.getBytes("iso-8859-1");
    s=new String(temp);
    }catch(UnsupportedEncodingException e){
    System.out.println(e.toString());
    }

    return s;
    }
      

  3.   

    在tomcat中的conf目录下有一个servet.xml 文件,将里面的<Connector port="8080" protocol="HTTP/1.1" 
                   connectionTimeout="20000" 
                   redirectPort="8443">改为<Connector port="8080" protocol="HTTP/1.1" 
                   connectionTimeout="20000" 
                   redirectPort="8443" URIEncoding="gb2312"/>就行了
      

  4.   


    __spmc = request.getParameter("namespmc") ;
         __spmc1 = new String(__spmc.getBytes("ISO8859-1"),"GB2312") ;
         __spbm = request.getParameter("namespbm") ;
    不行就返过来。。<% request.setCharacterEncoding("gb2312"); %>去掉试试
    多试试就行了。
      

  5.   


    __spmc = request.getParameter("namespmc") ;
         __spmc1 = new String(__spmc.getBytes("ISO8859-1"),"GB2312") ;
         __spbm = request.getParameter("namespbm") ;
    不行就返过来。。<% request.setCharacterEncoding("gb2312"); %>去掉试试
    多试试就行了。
      

  6.   

    String(byte[] bytes, String charsetName)  这样就应该可以了
      

  7.   

    改为
    <%@ page contentType="text/html;chatset=utf-8"%>
      

  8.   

    改为
    <%@ page contentType="text/html;chatset=utf-8"%>
    or
    <%@ page contentType="text/html;chatset=GBK"%>
    试试。
      

  9.   

    路过
      jf
    把请求编码设为 GBK
    把响应编码设为 GBK
    自己手动转码也行 
    String a = "中文";
    String str = new String(a.getBytes("ISO8859-1"),"GBK");写一个编码过滤器也行
    写一个编码过滤器这种方法最好