这样传汉字一般都会成乱码,如果你用的Web服务器是Tomcat我倒是有解决办法。

解决方案 »

  1.   

    UTF-8是处理英文字符串的,
    把他改成GB2312就可以了String name=request.getParameter("name"); 
    name=new String(name.getBytes("GB2312")); 
    System.out.println(name); 
      

  2.   

    String name=request.getParameter("name"); 
    name=new String(name.getBytes("ISO-8859-1"),"GB2312"); 
    System.out.println(name); 
      

  3.   

    乱码无非就是Tomcat,Filter 配置就可以解决了
      

  4.   

      
    public class SetCharacterEncodingFilter implements Filter { protected String encoding = null;
     public void doFilter(ServletRequest request, ServletResponse response,
                             FilterChain chain)
    throws IOException, ServletException {          String encoding = selectEncoding(request);
                if (encoding != null)
                    request.setCharacterEncoding(gb2312);
            } // Pass control on to the next filter
            chain.doFilter(request, response);    }
      public void destroy() {        this.encoding = null;
                }}
      

  5.   


    转码过滤器源代码如下:
    public class SetCharacterEncodingFilter implements Filter { protected String encoding = null; 
    public void doFilter(ServletRequest request, ServletResponse response, 
                            FilterChain chain) 
    throws IOException, ServletException {           String encoding = selectEncoding(request); 
                if (encoding != null) 
                    request.setCharacterEncoding(gb2312); 
            } // Pass control on to the next filter 
            chain.doFilter(request, response);     } 
      public void destroy() {         this.encoding = null; 
                } }
      

  6.   

    我的那个服务器是tomcat我先前已经写了个编码过滤器 我过滤的字符集是UTF-8 这里我要考虑到国际化的问题所以用了UTF-8了 还有我还在tomcat中已经加了URIEncoding="UTF-8"这样写了 可是以上的乱码问题还是没有解决我通过URL传递的中文参数(通过表单传递过来的中文参数已经可以解决了)兄弟在帮我看看怎么解决了 
      

  7.   

    我的那个服务器是tomcat我先前已经写了个编码过滤器 我过滤的字符集是UTF-8 这里我要考虑到国际化的问题所以用了UTF-8了 还有我还在tomcat中已经加了URIEncoding="UTF-8"这样写了 可是以上的乱码问题还是没有解决我通过URL传递的中文参数(通过表单传递过来的中文参数已经可以解决了)兄弟在帮我看看怎么解决了