Home >Backend Development >C#.Net Tutorial >Summary on the method of passing Chinese characters behind the URL
Test environment:
Server tomcat5.0,
Development tool Myeclipse6.5,
Filter has been configured, encoding utf-8.
Method 1: Modify Tomcat configuration
Assume that the web service uses 8080 as the port, modify /conf/server.xml, and add the red paragraph
3793d042d9bb902f2d17c16e36523ded
Pass value code
Jsp code
var url= "/yourwebapp/test.do?field1=测试例子"; window.open(url, "", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,top=192,left=256,width=650,height=350");
Get value code
Java code
String field1=request.getParameter("field1"); if(null == field1) { field1=request.getParameter("field1").trim(); }
Method 2: Use java.net.URLEncoder and java.net.URLDecoder
Assuming that method 1 is not used, you can use the second method.
Pass value code
Jsp code
var url= "/yourwebapp/test.do?field1=<%=java.net.URLEncoder.encode("测试例子","UTF-8")%>"; window.open(url, "", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,top=192,left=256,width=650,height=350");
Get value code
Java code
String field1=request.getParameter("field1"); if(null == field1) { field1=request.getParameter("field1").trim(); field1=java.net.URLDecoder.decode(field1,"UTF-8"); //tomcat默认使用ISO-8859-1进行URLEncoding,需要将其转换成我们需要的编码 field1=new String(field1.getBytes("ISO-8859-1"),"UTF-8"); }