get方法传参数乱码解决方法

首先在JSP页面要设成UTF-8
<%@ page pageEncoding="utf-8"%>
<%@ page contentType="text/html; charset=utf-8" %> 


然后在服务器端
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("utf-8");


TOMCAT6.0以上
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/>


TOMCAT5.5以上
<Connector port="8080" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="utf-8"/>


URIEncoding="utf-8"
但是直接在浏览器里面输入中文传过去还会是乱码
所在在生成连结的时候用JAVASCRIPT的encodeURI()和decodeURI()
  	function test(){ 
  		var b = encodeURI("http://localhost:8080/StudyWeb/langhua?name=浪花A");
  		location.href = b;
  		alert(decodeURI(b));
  	}

这样的话GET和POST方法传过来的参数就不会乱码了
生成的连结也不会有中文了

你可能感兴趣的:(JavaScript,html,xml,jsp,浏览器)