Solution: encode the Chinese parameter twice before passing the parameter. After obtaining the parameter on the JSP page, decode the Chinese parameter once. The Chinese parameter will not become garbled!
Example:
<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8"
Pageencoding = "UTF-8" %>
<% @ Page import = "java.net. *" %>
<%
String str0 = "";
String str1 = "";
If (request. getparameter ("param0 ")! = NULL ){
Str0 = request. getparameter ("param0"); // get Chinese parameters directly
}
Try {
If (request. getparameter ("param1 ")! = NULL ){
Str1 =Urldecoder. Decode ( Request. getparameter ("param1 "), " UTF-8 ") ; // Decodes Chinese Parameters
}
} Catch (exception e ){
E. printstacktrace ();
}
%>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<SCRIPT type = "text/JavaScript">
VaR STR = "hello ";
Function test0 (){
Window. Location = "test. jsp? Param0 = "+ STR; // directly pass Chinese Parameters
}
Function test1 (){
Window. Location = "test. jsp? Param1 = "+ Encodeuri ( Encodeuri ( Str ) ) ; // Encode Chinese parameters and pass them again
}
</SCRIPT>
</Head>
<Body>
<Input value = <% = str0 %>
<Input type = "button" value = "garbled" onclick = "test0 ()"> <br>
<Input value = <% = str1 %>
<Input type = "button" value = "normal" onclick = "test1 ()">
</Body>
</Html>