1. garbled Chinese characters may occur when the request object processes get and post requests:
Tomcat processes get and post requests in different ways.
A POST request stores parameters in the message body of the request data packet.
Therefore, you can use request. setcharacterencoding ("UTF-8 ");
However, the GET request stores the parameters in the URL, and setcharacterencoding does not work at this time. At this time, we need to use handwritten code for transcoding. (Because Tomcat automatically performs iso8859-1 encoding on the GET request generated URL)
E.g .:
String name = new String(request.getParameter("username").getBytes("iso-8859-1"),"utf-8");
You can also modify the tomcat configuration:
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="true" />
But I tried it myself and somehow it seems ineffective ......
2. Execute forward and include for the request object
The httpservletrequest class provides a getrequestdispatcher (string path) method, where path is the target path of forward/include and returns requesdispatcher. This object provides the following two methods:
Forward (servletrequest request, servletresponse response): Execute forward; Include (servletrequest request, servletresponse response): Execute include;
The call is as follows:
request.getRequestDispatcher("/a.jsp").include(request, response);request.getRequestDispatcher("/a.jsp").forward(request, response);
The forward method has the same effect as the JSP: Forward label, but the include method has different effects with the JSP: Include label:
After the include method is called, the content in path is first loaded into the returned page, and then the content of the current page;
The JSP: Include label loads the content in path at any position.
Note that the character string in path must start.
Continue Learning, Hoho !~