解决方案 »

  1.   

    首先保证页面的编码统一都是UTF-8,不行就用js的encodeURI处理一下试试,这个是客户端编码不一致造成的。
      

  2.   

    是不是可以在获取后转一下码,String inputPath =new String(inputPath.getBytes(iso-8859-1),"gb2312");
      

  3.   

    String inputPath =new String(<s:property value="link"/>">.getBytes(gb2312),"iso-8859-1")
    先转再传,直接传和这个意思一样
    <a href="download.action?inputPath=<s:property value="inputPath"/>"> 
    收到以后转回来
    String inputPath =new String(<s:property value="link"/>">.getBytes(iso-8859-1),"gb2312")
      

  4.   

    前台后台编码统一一下
    或者写个filter
    public class EncodingFilter implements Filter { public void destroy() {
    // TODO Auto-generated method stub

    } public void doFilter(ServletRequest arg0, ServletResponse arg1,
    FilterChain arg2) throws IOException, ServletException {
    //强制转换request类型
    HttpServletRequest req = (HttpServletRequest) arg0;
    //定义一个request的包装好的对象
    MyRequestWrapper request = new MyRequestWrapper(req);
    //设置request请求的字符编码
    request.setCharacterEncoding("UTF-8");
    //设置返回给浏览器的字符编码
    arg1.setContentType("text/html; charset=UTF-8");
    arg2.doFilter(request, arg1); } public void init(FilterConfig arg0) throws ServletException {
    // TODO Auto-generated method stub

    }
    class MyRequestWrapper extends HttpServletRequestWrapper{ private String charset = "UTF-8";
    public MyRequestWrapper(HttpServletRequest request) {
    super(request);
    }
    /**
     * 初始化字符编码
     * @param request
     * @param charset
     */
    public MyRequestWrapper(HttpServletRequest request,String charset) {
    super(request);
    this.charset = charset;
    }
    /**
     * 重写getParameter方法,
     */
    public String getParameter(String name){
    String value = super.getParameter(name);
    if(value==null){
    return null;
    }
        try {
         //如果方法名以get开头,则将里面的参数转为UTF-8类型
         if("GET".equals(this.getMethod())){
    value = new String(value.trim().getBytes("ISO-8859-1"),"UTF-8");
         }
    } catch (UnsupportedEncodingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return value;
    }

    }
    }
    然后在web.xml中配置下
      

  5.   

    提供两个方法:
    1. 修改tomcat配置文件 server.xml ,在tomcat目录下的conf中 
    找到这段代码:
    <Connector 
    port="8080" 
    protocol="HTTP/1.1" 
             connectionTimeout="20000" 
              redirectPort="8443" 
    />
    在其中添加一句 URIEncoding="UTF-8" 
    即:
    <Connector 
    port="8080" 
    protocol="HTTP/1.1" 
             connectionTimeout="20000" 
              redirectPort="8443" 
             URIEncoding="UTF-8"
    />
    重启服务器 ok2.前后台进行编码统一
    前台改为:<a href="download.action?inputPath=encodeURI(encodeURI(<s:property value="link"/>))">
    后台获取:try {
       inputPath=java.net.URLDecoder.decode(inputPath, "UTF-8");
        } catch (UnsupportedEncodingException e1) {
      e1.printStackTrace();
       }
      

  6.   

    一定主意在前台用两次encodeURI
      

  7.   

    现在tomcat服务器加URLEncoding=“utf-8”,如果不行就自己在后台获取值之后进行转吧
    String inputPath =new String(inputPath.getBytes(iso-8859-1),"utf-8");
      

  8.   

    new String(inputPath.getBytes(iso-8859-1),"gb2312");可以解码啊
      

  9.   

    先在前台利用encodeURI :
    encodeURI(encodeURI(search)) ;
    然后在后台进行解码 :
    String query= java.net.URLDecoder.decode(request.getParameter("parameter"), "UTF-8")
      

  10.   

    看看jsp、tomcat,项目编码是否一致,如果一致的话是不需要转码的,也不会出现乱码
      

  11.   

    超链接发送的是get请求,试下get请求的乱码解决方法:
    step1.在tomcat的server.xml配置文件的connector项添加 URIEncoding='UTF-8' ,这样容器就会按照UTF-8解码;
    step2.对请求参数使用 encodeURI(请求参数) 进行编码,这是js内置的对象,会使用UTF-8进行编码。
      

  12.   


    看看你页面最上面创建的是什么编码格式如果不是UTF-8可以加上
    或者后台接收参数时进行编码格式转换
    String value = new String (request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
    如果以上都解决不了的话   可能是数据库编码设置问题
    MYSQL一般会出现这样的问题 可以用以下方法查看编码格式其中,character_set_client为客户端编码方式;character_set_connection为建立连接使用的编码;character_set_database数据库的编码;
    character_set_results结果集的编码;
    character_set_server数据库服务器的编码;
    只要保证以上四个采用的编码方式一样,就不会出现乱码问题。