建议在jsp中汉字用espace刷换,在java中用
/*
 * 转换码
 */
public static String  unescape(String src){
        StringBuffer tmp = new StringBuffer();
         tmp.ensureCapacity(src.length());
         int  lastPos=0,pos=0,vpos=0;  char ch;String strout="";
         int srclength=src.length();
         while (lastPos<srclength){
            pos = src.indexOf("%u");
             if (pos != -1){
                 //if (src.charAt(pos+1)=='u'){
                     ch = (char)Integer.parseInt(src.substring(pos+2,pos+6),16);
                   tmp.append(ch);
                   strout=strout+src.substring(0,pos)+ch;
                   
                    lastPos = pos+6;
                    src=src.substring(pos+6); 
                //}
                 /*
else{
                    ch = (char)Integer.parseInt(src.substring(pos+1,pos+3),16);
                   tmp.append(ch);
                    lastPos = pos+3;
                }
                */
            }else{
            
             //vpos=src.indexOf("%",lastPos);
                if (pos == -1){
                    //tmp.append(src.substring(lastPos));
                    strout=strout+src;
                    lastPos=srclength;
                }else{
                    tmp.append(src.substring(lastPos,vpos));
                    lastPos=vpos;
                }    
            }  
        }  
        return strout; 
    }  
转换,这样不管在什么web服务器下都能正常显示了

解决方案 »

  1.   

    1、  对于同一个应用,最好统一编码,推荐为UTF-8,当然GBK也可以。2、  正确设置JSP的pageEncoding参数3、  在所有的JSP/Servlet中设置contentType="text/html;charset=UTF-8"或response.setCharacterEncoding("UTF-8"),从而间接实现对浏览器编码的设置。4、  对于请求,可以使用过滤器或者在每个JSP/Servlet中设置request.setCharacterEncoding("UTF-8")。同时,要修改Tomcat的默认配置,推荐将useBodyEncodingForURI参数设置为true你的问题可能是没有将tomcat里默认配置修改,useBodyEncodingForURI=true
    如果没有改这个配置,可能出现的情况就是,凡是在jsp中有做超链接传递中文字符的参数
    传递到后台程序中就变成乱码了,你再从后台输出到前台,当然也是乱码了
      

  2.   

    忘记说了,要修改tomcat里conf子目录下的server.xml文件
    把8080端口的配置加一个 useBodyEncodingForURI=true
    就可以解决由于超链接传递中文字符出现的乱码问题了
      

  3.   

    是在server.xml里修改这一行吗?
    “<!-- Define a non-SSL Coyote HTTP/1.1 Connector on the port specified during installation  -->
      <Connector port="8080" ..在这里加吗?...disableUploadTimeout="true" />     ”
    可是我加上了useBodyEncodingForURI=true后网页打不开了,去掉后又能打开了 奇怪!
    response.setCharacterEncoding("UTF-8")和
    request.setCharacterEncoding("UTF-8")这两句如何加在JSP文件中?请给个小例子
    这个系统的JSP文件大大小小有60多个,全部加上这些设置恐怕要累死,有没其他方法统一设置编码UTF8?