javascript中有时需要向后台传递中文参数,再次展示到前台时显示为乱码,解决方案:
方案1:修改Tomcat-conf-server.xml文件
大约69-71行 修改为:
      
        <
      
      
        Connector 
      
      
        port
      
      
        ="8080"
      
      
         protocol
      
      
        ="HTTP/1.1"
      
      
         
               connectionTimeout
      
      
        ="20000"
      
      
         
               redirectPort
      
      
        ="8443"
      
      
         URIEncoding
      
      
        ="utf8"
      
      
        />
      
    
  方案2:设置servlet字符集:
在java代码中加入:
      response.setContentType("text/html; charset=UTF-8"
      
        );
        response.setCharacterEncoding(
      
      "UTF-8"
      
        );
        request.setCharacterEncoding(
      
      "UTF-8");
    
  方案3:
    1.使用js对参数进行URL编码
    
  
      
        var
      
       _name=encodeURI($("#name").val()); 
      
        //
      
      
        编码
      
    
  2.在服务端解码
      String _name=URLDecoder.decode(areaDTO.getName(),"utf-8");
    
  


 
					 
					