Home  >  Article  >  Backend Development  >  Summary on the method of passing Chinese characters behind the URL

Summary on the method of passing Chinese characters behind the URL

巴扎黑
巴扎黑Original
2016-12-20 15:59:301667browse

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


Statement:
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