Request to solve Chinese garbled characters

Source: Internet
Author: User

Package request;

Import java. Io. ioexception;
Import javax. servlet. servletexception;
Import javax. servlet. http. httpservlet;
Import javax. servlet. http. httpservletrequest;
Import javax. servlet. http. httpservletresponse;

Public class requestdemo4 extends httpservlet {

Protected void doget (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
// What is the form page data sent from? The table controls the request to be read from? The table
// Fix Chinese garbled characters submitted by post
Request. setcharacterencoding ("UTF-8"); // valid only for post submission
System. Out. println (request. getparameter ("username "));


// Solve the garbled problem by submitting data in get Mode
// Because request. setcharacterencoding ("UTF-8") is only valid for data submitted in post Mode
// Therefore, the data submitted in get mode can only be manually solved.
// The request uses the iso8859 encoding by default. The data we query corresponds to the encoding in iso8859, and then the corresponding value is in UTF-8? Check the corresponding value in the table.
String name = request. getparameter ("username ");
// Solve the Chinese Garbled text submitted by get. It is also applicable to data submitted by hyperlink ------- The amount of data submitted by hyperlink is submitted by get.
Name = new string (name. getbytes ("iso8859-1"), "UTF-8 ");
System. Out. println (name );
}


Protected void dopost (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
Doget (request, response );
}

}

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.