Transcoding: a. href = "./showCont. jsp? Tcontent = "+ encodeURI (tcontent ));
Decoding: java.net. URLDecoder. decode (String) request. getParameter ("tcontent"), "UTF-8 ");
Example
A. jsp source code
Copy codeThe Code is as follows:
<% @ Page contentType = "text/html; charset = gb2312" language = "java" import = "java. SQL. *" errorPage = "" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
</Head>
<Body>
<%
String str_test = "";
%>
<Form method = post action = "B. jsp? Test = <% = java.net. URLEncoder. encode (str_test) %> ">
<Input type = "submit" value = "Submit" name = "submit">
</Form>
</Body>
</Html>
B. jsp source code
Copy codeThe Code is as follows:
<% @ Page contentType = "text/html; charset = gb2312" language = "java" import = "java. SQL. *" errorPage = "" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
</Head>
<Body>
<%
String str = new String (request. getParameter ("test"). getBytes ("ISO8859_1 "));
%>
<BR>
<% = Str %>
</Body>
</Html>