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 );
}
}