JSP built-in object-Chinese garbled processing of data sent from the request, jsp-request
The built-in request object of JSP can receive the parameter information sent from the client, that is, the information submitted by the user. However, garbled characters (Chinese only) occur when requesr obtains the Chinese character information submitted by the client ).
We can re-encode the Chinese character. It's easy to read the code:
We first create a client information submission page to submit Chinese characters:
Now we create a new server receiving page to display the parameter information sent from the client:
We can see that garbled characters occur when we use the JSP built-in object request to receive and display parameters sent from the client.
To solve this problem, we only need to re-encode the parameters sent from the request, just a simple line of code: Now let's take a look at the results:
Now we can normally display the Chinese characters sent from the client. It may be very simple for everyone. However, sometimes it is very useful to re-encode Chinese characters because it cannot produce normal results.
For JSP problems, all the characters that I use the request object to receive Chinese characters are garbled.
Take a look at the page encoding, if it is UTF-8
Then write
String username = new String (request. getParameter ("username"). getBytes ("iso-8859-1"), "UTF-8 ");
Chinese garbled characters when retrieving data submitted by forms in JSP
Written in jsp file <% @ page contentType = "text/html; charset = GBK" %>
Only valid for post. request. setCharacterEncoding ("gbk"); this code is generally placed at the beginning. The above line of code can only be set before getParameter (), otherwise this code is invalid.