java前台传中文到后台乱码问题,还有浏览器的差异

前台通过url的形式传中文参数,后台用
String parvalue = new String( request.getParameter("parvalue").getBytes("ISO8859-1"), "utf-8");
这样接受,在谷歌浏览器上没问题,但在IE浏览器,QQ浏览器上却是乱码。

然后换个方式,前台url += "&area=" + encodeURIComponent(area);这样编码一次,后台还是乱码,而且在谷歌浏览器也不行了。

请大虾们帮帮忙

tomcat找到配置文件server.xml
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8"/>
找到你用的端口,添加编码

前台转码,后台解码

例如:前台jsp中:

var groupBuyerName = document.getElementById('groupBuyerName').value;
groupBuyerName = encodeURI(encodeURI(groupBuyerName));

后台java类中:

String groupBuyerName = request.getParameter("groupBuyerName")
groupBuyerName=URLDecoder.decode(groupBuyerName,"utf-8");

还有可能是你使用的服务器的问题,tomcate可以配置URIEncoding属性,指定get操作的请求参数编码的方式的。

编码有问题现在这几个有没有设置
(1).项目web.xml编码设置:页面显示和传参乱码,可能是web.xml没配置请求编码,这里需要加上以下配置就ok:

<filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>
        org.springframework.web.filter.CharacterEncodingFilter
    </filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<!--spring编码过滤器end -->
    (2).tomcat 的service.xml加上编码设置
    <Connector port="8080"  protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />