How can a webpage written in JSP contain Chinese characters when passing parameters? 2011-06-21 17: 58 yuqiangdede
| Category: other programming languages | browsing 428 times
<% @ Page contenttype = "text/html; charset = gb2312" %> <a href = "cartservlet? Action = SEARCH & cname = <% = sT %> "><%= st %> </a> request in servelt. setcharacterencoding ("gb2312"); response. setcontenttype ("text/html; charset = gb2312"); response. setcharacterencoding ("gb2312"); string cname = request. getparameter ("cname"); is the cname garbled? How can this problem be solved? Thank you. It is best not to use a filter ~
Wonderful answer
Request. setcharacterencoding is set to use gb2312 for transcoding. There will be no problems here. The key is to look at your page .. the page uses hyperlinks, And the hyperlink uses the get Method for requests. How to send the parameter part to the server depends on the browser and related settings: URI in IE uses utf8 for escape, the second half uses utf8 to encode Firefox, and the page encoding is used for escape. So you can open it in Firefox to see if it can be obtained normally? To completely solve the problem, do not include Chinese characters in the URL Uri and parameter section in cname = <% = sT %> "> first encode ST = urlencoder. encode (St, "gb2312"); --- convert to % & * & (^ & this kind of unreadable stuff, you can also view the page source code. After that, when the browser sends a request, encoding and escaping will not be processed (there are no special characters such as Chinese characters), so the server can get the correct gb2312 escape character information.
-
Question
-
Oh, I used cname in servelt to construct the SQL statement result. The cname is % CB % AE % B9 % FB, and MySQL uses gb2312. Can I convert the code into Chinese?? JSP is a problem at the beginning ~~ Thank you.
-
Answer
-
This heap is not garbled, It is the escape Code; it is similar to converting back to Chinese: urldecoder. Decode (STR, "gb2312 ")
-
Comments from the questioner
-
Thank you very much ~
Comment |
1
Littleatp | the acquisition rate of Level 6 is 49%.
Good at: Java
Sort by default | sort by Time
Other 2 answers 21: 14wu1g | level 5
Chinese characters are garbled in get. A stupid method does not need get, and all values are submitted in forms. This is definitely not garbled in Chinese, example <% @ page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%> <% string Path = request. getcontextpath (); string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/"; %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML> Comment |
02011-06-21 18: 04caesar1800 | level 5
Before uploading, first convert the parameter encoding ST = urlencoder. encode (St, "gb2312 ");