我的问题是:
http://localhost:8088/strutstest/login.do?name=刘 
程序中这样接收参数的如下: 
String name=request.getParameter("name"); 
//name=new String(name.getBytes("UTF-8")); //这里我硬编码改变还是会乱码
System.out.println(name); 
为什么这样还是乱码啊? 我的那个服务器是tomcat我先前已经写了个编码过滤器 我过滤的字符集是UTF-8 这里我要考虑到国际化的问题所以用了UTF-8了 还有我还在tomcat中已经加了URIEncoding="UTF-8"这样写了 可是以上的乱码问题还是没有解决我通过URL传递的中文参数(通过表单传递过来的中文参数已经可以解决了)兄弟在帮我看看怎么解决了

解决方案 »

  1.   

    通过get方式提交中文是会出现乱码的问题。这里提交之前应该先用java.net.URLEncoder类,将中文编码,编码之后的参数就可以以get方式提交了,接收到参数后,还要以java.net.URLDecoder类来解码,这样就可以解决get方式提交中文的乱码问题
      

  2.   

    你用GBK  你的过滤器可能没有起作用
      

  3.   

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC 
       "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
       "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
    <constant name="struts.i18n.encoding" value="GBK"></constant>
    <package name="default" extends="struts-default">
    <action name="register" class="org.sunxin.struts2.action.RegisterAction">
    <!-- 配置映射异常,当registerAction 抛出Exception异常的时候,向
    用户显示error.jsp页面 -->
    <exception-mapping result="error" exception="java.lang.Exception"/>

    <result name="input">/WEB-INF/pages/register.jsp</result>
    <result name="success">/WEB-INF/pages/success.jsp</result>
    <result name="error">/WEB-INF/pages/error.jsp</result>
    </action>
    </package>
    </struts><constant name="struts.i18n.encoding" value="GBK"></constant>这句加到你的structs.xml中
      

  4.   

    这个URLDeCoder没试过,只有用POST去解决,form提交。
      

  5.   

    URLDecoder是要和URLEncoder配合使用的,URLEncoder将中文编译成那种一长串的特殊字符就可以使用get来提交了,URLDecoder再将特殊字符转换成中文
      

  6.   

    String name=request.getParameter("name"); 
    name=new String(name.getBytes("UTF-8"),"GB2312"); 
    System.out.println(name); 只要你的过滤器起作用了,式一下上面这样看可以不?
    主要是这一句
    name=new String(name.getBytes("UTF-8"),"GB2312"); 
    或者这样
    name=new String(name.getBytes("UTF-8"),"GBK"); 
      

  7.   

    还有我还在tomcat中已经加了URIEncoding="UTF-8"这样写了这一句去掉吧,呵呵,其实我也是前面段时间一位师兄给我说的,去掉它,
    做了过滤器就OK了,你所有的都采用UTF-8?是不是编译环境都是?如果不是,重新建立工程拷贝进去吧,还有就是转码,你多试几次打印就可以解决了,乱码问题由来已久了,不是多难,多遇到,多解决就OK了
      

  8.   


    设置一个 字符 过滤器或者 new String(name.getBytes("UTF-8"),"GB2312"); 
      

  9.   

    如果是struts2的话,在配置文件中加:<constant name="struts.i18n.encoding" value="GBK"></constant>
    struts1的话,写个过滤器:
    import java.io.IOException;
    import java.io.UnsupportedEncodingException;
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;public class EncodingFilter implements Filter {
    public EncodingFilter() {
    } public void init(FilterConfig filterconfig) throws ServletException {
    filterConfig = filterconfig;
    } public void doFilter(ServletRequest servletrequest,
    ServletResponse servletresponse, FilterChain filterchain) {
    String s = filterConfig.getInitParameter("encoding");
    if (s == null)
    s = "GB2312";
    s = s.trim();
    if (s.length() == 0)
    s = "GB2312";
    try {
    servletrequest.setCharacterEncoding(s);
    } catch (UnsupportedEncodingException unsupportedencodingexception) {
    System.out
    .println("\u8F6C\u7801\u51FA\u9519\uFF01\u76EE\u6807\u7F16\u7801["
    + s + "]");
    }
    try {
    filterchain.doFilter(servletrequest, servletresponse);
    } catch (ServletException servletexception) {
    filterConfig.getServletContext().log(servletexception.getMessage());
    } catch (IOException ioexception) {
    filterConfig.getServletContext().log(ioexception.getMessage());
    }
    } public void destroy() {
    } private FilterConfig filterConfig;
    }