Jsp+servlet Chinese garbled problem

Source: Internet
Author: User

One.

Because Doget and dopost are handled differently, there is a problem when doing a servlet: The parameters obtained with Dopost are added "request.setcharacterencoding (" Utf-8 ") as a line, The display of Chinese will not garbled, but the parameters obtained by doget with "request.setcharacterencoding (" Utf-8 ")" This line is still garbled, the solution is as follows:

1. This one is a once and for all method, found from the Internet
Locate the Conf/server.xml file in your Tomcat server root directory, locate the line in the file, and change the uriencoding= "" double quotation mark inside to Utf-8, which is the red font.
As follows:
<connector port= "8080" protocol= "http/1.1"
connectiontimeout= "20000"
Redirectport= "8443" uriencoding= "Utf-8"/>

2. The following method is taught by a teacher, such as:

String name=request.getparamter ("name");

String Username=new string (name.getbytes ("iso-8859-1"), "Utf-8");

This is forced transcoding using the transcoding function of the string. Note:. GetBytes () If it is a Chinese operating system, the default is to use GB2312 encoding.

Two.

Use the output to the page in the following way: Response.setheader ("Content-type", "text/html;charset=utf-8");

Jsp+servlet Chinese garbled problem

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.