在jsp中需要用get方法传递一个中文名称来检测账号是否存在,我的web.xml中配置了utf-8的filter,在jsp中我配置有:
<%@ page language="java" pageEncoding="utf-8"%>   
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">   
<html>   
    <head>   
    <title>用户注册信息</title>          
         </head>   
        function userCheck() {   
            var uname = document.registerForm.org_loginname.value;   
            if(uname=="") {   
                window.alert("用户名不能为空!");   
                document.registerForm.org_loginname.focus();   
                return false;   
                }   
            else {   
                sendRequest('register.do?method=checkuser&username='+ uname);   
                    }   
                }   
            </script>
action中如下:
public ActionForward checkuser(ActionMapping mapping, ActionForm form,   
            HttpServletRequest request, HttpServletResponse response)  throws Exception{   
    String username = new String(request.getParameter("username").getBytes("ISO-8859-1"),"utf-8");   
    System.out.println("username:"+username);      
}  
在tomcat的server.xml中的配置如下:
<Connector port="8088" protocol="HTTP/1.1"    
              connectionTimeout="20000" useBodyEncodingForURI="true"    
              redirectPort="8443" URIEncoding="UTF-8" />   
   
这样输出来的usrname 还是乱码,我在网上搜的解决方法都是这样改了后就没事了,我的怎么还是会出现乱码呢?

解决方案 »

  1.   

    1 最好不要在url里面传递中文参数,如果传递,应该先编码好在传递
    2 ajax支持post提交
      

  2.   

    已经设置了utf-8的filter,还用ISO-8859-1来编码,不乱码才怪
      

  3.   

    楼上正解 。。
    去掉filter或者 
    直接
    String username = request.getParameter("username);
      

  4.   

    可以用js对中文进行编码后再传输,参考这个javascript Encoder UTF-8 汉字编码
      

  5.   

    你想在一个<a href="clientQuery.do?method=kMessageQuery&gid=${gbmes.GId}&bsname=<%=java.net.URLEncoder.encode(${gbmes.bsname},"utf-8") %>height=290&width=500" class="thickbox">关键信息</a>
    bsname=<%=java.net.URLEncoder.encode(${gbmes.bsname},"utf-8") %>不能这么直接编码啊。
      

  6.   

    你的utf-8的filter怎么写的。
    如果你的filter是正确的,那就和 String username = new String(request.getParameter("username").getBytes("ISO-8859-1"),"utf-8");  重复了。
    这里不需要再转码了。
      

  7.   

    这个问题也困扰了我很久,今天终于解决了,非常感谢,就是把tomcate下加一个<Connector port="8088" protocol="HTTP/1.1"   connectionTimeout="20000" useBodyEncodingForURI="true" redirectPort="8443" URIEncoding="GBK" />  
      

  8.   

    我用的是websphere服务器,该怎么办啊?