Example of passing Chinese parameters between JSP pages

Source: Internet
Author: User
Tags xmlns

  in the URL address bar using Chinese to pass the parameters may be garbled, let's look at the correct JSP in the page to pass the Chinese parameter transcoding method  

transcoding:     Code as follows: a.href= "./showcont.jsp?tcontent=" +encodeuri (encodeURI (tcontent));     decoding:   code as follows: Java.net.URLDecoder.decode ((String) request.getparameter ("Tcontent"), "UTF-8");     Example a.jsp source code     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 = "Chinese laborers"; %>  <form method=post action= "b.jsp?test=<% =java.net.urlencoder.encode (str_test)%> ">           <input type=" Submit "value = "Submit" Name= "submitted" > &nbsP </form>   </body>  </html>       b.jsp source code     code as follows: <%@ page Conten Ttype= "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")); %& gt;  <BR>  <%=str%>  </body>   
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.