Summary on the method of passing Chinese characters behind the URL

巴扎黑
Release: 2016-12-20 15:59:30
Original
1633 people have browsed it

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


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");
Copy after login

Get value code

Java code

String field1=request.getParameter("field1");  
if(null == field1)  
{  
    field1=request.getParameter("field1").trim();  
  
}
Copy after login



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");
Copy after login

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");  
}
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!