There are two main ways to pass Chinese parameters in JSP pages:
URL way, for example: http://website/test1.jsp?act=add&type= Orange ¶m=%20d%20b
form, for example:
<form name=test mehtod= "POST" >
<input type=hidden name=text2 value= "Chinese" >
<input Type=text name=text1>
<input Type=submit value=submit>
</form>
The following two cases provide a solution for the correct delivery of Chinese
Way 1:url Way
For example: http://website/test1.jsp?act=add&type= Orange ¶m=%20d%20b
Generally speaking, we rarely write the parameters in Chinese directly in the URL, such as "Type= orange" in the example. If this happens, we just need to make a simple conversion on our receiving parameter page.
Code test1.jsp: (main part)
<%@ page language= "java" import= "java.util.*" pageencoding= "gb2312"%>
<%
String type = Request.getparameter ("type");
string result = new String (Type.getbytes ("iso-8859-1"), "gb2312");
OUT.PRINTLN (result);
%>
It is also more common to encode the Chinese characters in a URL into a character like type=%20d%20b.
Code myjsp1.jsp:
<%@ page language= "java" import= "java.util.*" pageencoding= "gb2312"%>
<%@ page import= "java.net.*"%>
<a href= './myjsp2.jsp?act=<%=urlencoder.encode ("The Beijingers are very good =-")%> ' >test</a>
Code myjsp2.jsp:
<%@ page language= "java" import= "java.util.*" pageencoding= "gb2312"%>
<%@ page import= "java.net.*"%>
String tempval = Urldecoder.decode (request.getparameter ("act"));
Out.println (New String (Tempval.getbytes ("iso-8859-1"), "gb2312");
Way 2:form Way
Note that we are only discussing the Chinese situation in <form enctype= "application/x-www-form-urlencoded" > This form, because in enctype= "Multipart/form-data" You can also use this method to convert characters by parsing them, so don't repeat the discussion.
<form method=post> This is the simplest case.
Code myjsp1.jsp:
<%@ page language= "java" import= "java.util.*" pageencoding= "gb2312"%>
<form action= "./myjsp2.jsp" method= "post" enctype= "application/x-www-form-urlencoded" >
<input type=hidden name=act value= action/>
<input Type=submit value=ok>
</form>
Code myjsp2.jsp:
<%@ page language= "java" import= "java.util.*" pageencoding= "gb2312"%>
Request.setcharacterencoding ("gb2312");
Out.println (Request.getparameter ("act"));
Or
<%@ page language= "java" import= "java.util.*" pageencoding= "gb2312"%>
String tempval = request.getparameter ("act");
Out.println (New String (Tempval.getbytes ("iso-8859-1"), "gb2312");
<form method=get> situation. Code myjsp1.jsp:
<%@ page language= "java" import= "java.util.*" pageencoding= "gb2312"%>
<form action= "./myjsp2.jsp" method= "Get" enctype= "application/x-www-form-urlencoded" >
<input type=hidden name=act value= action/>
<input Type=submit value=ok>
</form>
Code myjsp2.jsp:
<%@ page language= "java" import= "java.util.*" pageencoding= "gb2312"%>
String tempval = request.getparameter ("act");
Out.println (New String (Tempval.getbytes ("iso-8859-1"), "gb2312");
Another:
This article does not discuss the operation of encrypting a URL, but only the basic encoding of the URL's Chinese. In addition, in JavaScript you can use Escape (), encodeURI (), encodeuricompoent () for the relevant URL encoding, can be used as a reference solution for JavaScript Chinese encoding.