Encoding:
In JSP and Servlet, encoding can be set in the following aspects,
Pageencoding = "UTF-8", contenttype = "text/html; charset = UTF-8", request. setcharacterencoding ("UTF-8") and response. setcharacterencoding ("UTF-8 "),
Response. setcontenttype ("text/html; charset = UTF-8 ");
The first two can only be used in JSP, and the last two can be used in JSP and servlet.
JSP: pageencoding = "UTF-8" contenttype = "text/html, UTF-8"
JSP: first, the encoding method set by myeclipse is used to generate a file with the JSP extension that is saved on the local hard disk. During the first access, JSP files are compiled into files with the Java extension, and the compiled code is compiled into corresponding java files based on pageencoding = "UTF-8" in JSP, (eventually compiled into a file with the class extension) during compilation and translation into a Java file, if the encoding is different from the encoding stored in the JSP file, the encoding problem will occur (the strings defined in the JSP file will have problems, rather than the data submitted from the browser ),
In JSP, The contenttype = "text/html, UTF-8" command and the response. setcontenttype ("text/html; charset = UTF-
8 "); the method is the same
It is the encoding method used by the browser to respond to the server, that is, the encoding method used to unpack the data packets sent by the server. (A message header is generated when the browser sends the data packets to notify the browser of this encoding method) the browser also uses this method to package the data and send it to the server.
When a browser sends a data packet, should the server parse the data packet? So what is the encoding method for parsing data packets on the server? Request. setcharacterencoding () so that the server will parse the packets sent by the browser according to the specified encoding method