new String(request.getParameter("taskName").getBytes("8859_1"));

解决方案 »

  1.   

    方法一:<%@page contentType="text/html; charset=GBK"%> 方法二:String s="总类管理";
    byte[] sbyte=s.getBytes("ISO8859_1");
    s=new String(sbyte);或者strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK"); 例:public static String UnicodeToChinese(String s){
      try{
         if(s==null||s.equals("")) return "";
         String newstring=null;
         newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
         return newstring;
        }
      catch(UnsupportedEncodingException e)
      {
      return s;
      }
      }public static String ChineseToUnicode(String s){
      try{
      if(s==null||s.equals("")) return "";
      String newstring=null;
      newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
       return newstring;
      }
      catch(UnsupportedEncodingException e)
      {
      return s;
     }
     } *
     *文件名:Handle.java
     *实现功能:使用功能集合
     *
     *最后修改日期:2003-3-20
     */
    package com.ali.util;public class Handle {  public Handle() {}  /**
       *字符转换为中文编码
       *@param String
       *@return String
       */
      public static String getCh(String s) {
        try {
          String temp_s = s;
          byte[] sbyte = temp_s.getBytes("ISO8859_1");
          String temp = new String(sbyte);
          return temp;
        }
        catch (Exception e) {}
        return "null";
      }} //END Class Strtoch
      

  2.   

    用这个函数就可以了:
    public String getstr(String str)
    {
    try
    {
    String temp_str=str;
    byte[] temp_t=temp_str.getBytes("ISO8859-1");
    String temp=new String(temp_t);
    return temp;
    }
    catch(Exception e)
    {
    }
    return "null";
    }
      

  3.   

    ***********************************
    ***********************************
    更正:
    原因不是form提交的问题,而是
    a.html
    <input name="name" type="text" " id="name" >
    内容为“任务一”
    b.jsp
    String name=request.getParameter("name"); <jsp:forward page="c.jsp">
        <jsp:param name="sname" value="<%=name%>"/>
    </jsp:forward>
    c.jsp
    request.getParameter("name");显示“???”
      

  4.   

    b.jsp
    String name=new String(request.getParameter("name").getBytes("8859_1"));%><jsp:forward page="c.jsp">
        <jsp:param name="sname" value="<%=name%>"/>
    </jsp:forward>
    c.jsp:
    String namec=new String(request.getParameter("name").getBytes("8859_1"));%>
    namec is :<%=namec%>
      

  5.   


    在每个jsp页面的开头加上
    <%@ page contentType="text/html; charset=GBK" %>
    <%
    request.setCharacterEncoding("GB2312");//设置编码
    %>就可以了。
      

  6.   

    中文我也没弄好,进来学习。servlet默认用哪种编码?
      

  7.   

    从form提交过去的中文字符都是unicode 编码的,要正常显示,需要转换成gbk编码,方法前面几位说了
      

  8.   

    我不是用form 提交的,是用
    <jsp:forward page="c.jsp">
        <jsp:param name="sname" value="<%=name%>"/>
    </jsp:forward>
    相反form不用转换
      

  9.   

    不会吧,在我机器上可以的啊!!
    b.jsp
    <%@ page contentType="text/html;charset=gb2312" %>
    <html>
    <head>
    <title>无标题文档</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
    <body>
    <%
    String name=new String(request.getParameter("name").getBytes("8859_1"));  %>
    <jsp:forward page="c.jsp">
        <jsp:param name="sname" value="<%=name%>"/>
    </jsp:forward>
    </body>
    </htm>c.jsp:
    <%@ page contentType="text/html;charset=gb2312" %>
    <html>
    <head>
    <title>无标题文档</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
    <body>
    <%
    String namec=new String(request.getParameter("name").getBytes("8859_1"));%>
    namec is :<%=namec%>
    </body>
    </html>
    我用的是tomcat4.1.18!
      

  10.   

    推荐有resin,对中文的支持很好!
      

  11.   

    乱麻问题是跟操作系统和服务器软件有关的。
    Unix和windows的会有不同表现。
    上次使用Jbuilder的时候因为装的时候选的语言不一样,同样系统平台也是有的有乱麻,有的没有。呵呵,所以建议在开发之前一定要调查一下相关的字符问题,不然会很麻烦的。
      

  12.   

    试试 java.net.URLDecoder.decode(request.getParameter("taskName")); good luck!
      

  13.   

    试试 net.URLDecoder.decode(request.getParameter("taskName"));
      

  14.   

    大家说的都是治本不治根的方法,比如tomcat就是因为自己的服务端代码有问题导致出现乱码,所以需要修改代码
    象weblogic这个东西配置好编码就没有问题,resin我没用过,你看是否可以看看是否可以通过配置编码达到目的
    如果用的是tomcat,我可以提供如果修改tomcat代码达到目的
      

  15.   

    java.net.URLDecoder.decode(request.getParameter("taskName")); 不行
      

  16.   

    我用的也是Tomcat4.1.18为什么也不行?
    以前在jBuilder下用new String(strInString.getBytes("ISO-8859-1"),"gb2312");可以解决但后来用Tomcat时候就不行了?
      

  17.   

    我下了新的Resin2.1.9也不行啊,是不是配置时做了什么设置啊??
      

  18.   

    我的机器是两种情况:1、POST、GET方法得到的字符串如果有中文的话,只要在page 中设置contentType为gb2312就没有问题了。包括了用out等输出的中文也没有问题。2、当是从数据库中读取的时候,就必须要使用getBytes("ISO8859-1")然后to GBK或者GB2312的方法才行。我都快弄晕了。
      

  19.   

    <%@ page contentType="text/html;charset=ISO8859_1"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//ZH">这样也可以啦。。当把jsp页面 指定成ISO8859_1  就跟Tomcat ,JDK 一致了,不用写中文转换了而且移植到linux 也没问题
      

  20.   

    <%
        request.setCharacterEncoding("GBK");
    %>
      

  21.   

    只要一句.request.setCharacterEncodeing("gb2312");
      

  22.   

    不行,不行,
    没听明白我的意思,我说的不是用form提交的。而是用
    <jsp:forward ccc.jsp
    <jsp:param name=kdkd value=kdkd
    这种形式,这是一种特殊情况。
      

  23.   

    调用字符转换函数public String StringInfo(String strTemp){
        if(strTemp! = null && !StrTemp.equals("")){
            try{
                strTemp = new String(strTemp.getBytes("iso-8859-1"),"gb2312");
               }
            catch(Exception e){
                strTemp = null;
            }
        }
        return(strTemp);
    }页面出现乱码可以添加
    <%@ page contentType="text/html;charset=gb2312"%>
      

  24.   

    试了,不行。
    我用的是Tomcat4.1.18 Apache
      

  25.   

    在你的代码最前端增加一行代码:
    <%@page contentType="text/html;charset=gb2312"%> //最好所有的页面上都写上它
    .......................................
    String s = new String(request.getParameter("taskName").getBytes("8859_1")); 应该可以了.你试试.
      

  26.   

    String T_Name=new String (request.getParameter("member1").getBytes("ISO8859_1"),"GBK")
      

  27.   

    码制的问题挺复杂,那位大虾能在这终结一下给我们这学刚入门的学生听听!Thank you~~
      

  28.   

    各位老友。你们所说的在网页头上加<%@page contentType="text/html;charset=gb2312"%> 
    和使用转换函数只适合于Tomcat4.0以下版本。4.0以上版本根本就不适用。
    如果用post,get接受数据库中的值还是会出现乱码。而且在url中加中文参数也会出现乱码。
    所以各位朋友谁用Tomcat4.0以上软件的朋友来价绍一下经验。其它的朋友别来泡分了。
    大家说点实际的问题。难道中国的软件行业就真的跟着老外走吗?
    难道就真没高手了吗?
      

  29.   

    在1和2的页面都加上下面的两句话
    <%@ page contentType="text/html; charset=gb2312" %>
    <%request.setCharacterEncoding("gb2312")%>
    就可以了,
      

  30.   

    <%@ page language="java" %>
    <%@ page contentType="text/html; charset=gb2312" %>
    <%

        String msg = "只要你好";
    %>
    <jsp:forward page="forwardedit.jsp" >
        <jsp:param name="msg" value="<%=msg%>" />
    </jsp:forward>forwardedit.jsp
    <%@ page language="java" contentType="text/html; charset=gb2312" %>
    <%
    request.setCharacterEncoding("utf-8");
        String msg = null;
    msg = request.getParameter("msg");
        out.println(msg);
    %>这样就可以了,终于想到了答案,想了很久。