JSP built-in object-Chinese garbled processing of data sent from the request, jsp-request

Source: Internet
Author: User

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.


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.