A simple solution for garbled Chinese characters of JSP page values

Source: Internet
Author: User

Source code. a. jsp transmits values to B. jsp:

A. jsp page content:

Name:

B. jsp page content:

Symptom: Chinese characters are garbled, such as "???"

The solution is as follows:

Method 1:

1. Change pageEncoding = "GB2312" to pageEncoding = "ISO8859-1" in B. jsp"

Although the content displayed on the B. jsp page is garbled, it is not the type of "???" But some special characters.

2. Check the menu in the browser and modify the code to GB2312. Then, the Garbled text will display Chinese characters.

3. However, this method is not feasible.

Method 2:

1. In B. jsp, change String name = request. getParameter ("name");

String name = new String (request. getParameter ("name"). getBytes ("ISO-8859-1"), "GB2312 ");

2. Then it will be displayed on the page, which is Chinese.

Method 3:

1. Some people say that it is necessary to modify the get/post value transfer method. If you only change the get method to the post method, the page results will still be garbled!

2. You must configure a filter. If you only configure a filter, the value transmission method must be: post is not garbled, and get is garbled!

3. The configuration of the filter, I think everyone can have it. I will not talk about it anymore.

Method 4:

1. Some people say this sentence in the configuration file server. xml for tomcat:

Port = "8080" maxHttpHeaderSize = "8192"

MaxThreads = "150" minSpareThreads = "25" maxSpareThreads = "75"

EnableLookups = "false" redirectPort = "8443" acceptCount = "100"

ConnectionTimeout = "20000" disableUploadTimeout = "true"/>

URIEncoding = "GB2312"

2. Although yes, there are prerequisites. If your filter is not configured, you only Configure the server. xml file, so that you can only pass values in the form with get! When it is post, it is still garbled!

* In this case, we can see that the post and get methods in tomcat5 are different *

* Is there a way to use the get or post method for transferring values? The following is the recommended method 5 *

Method 5:

1. Actually, it is very simple, that is, implementing method 3 and method 4 at the same time!

2. Configure the filter and the server. xml file, both of which are encoded as GB2312.

3. In this way, no text is garbled in form values transmitted through post or get!

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.