We know that JSP pages need to be converted to servlets and must be encoded during the conversion process. The following code plays a critical role in translating the JSP into the servlet process.
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" GBK "%>
In the above code there are two places encoded: pageencoding, ContentType CharSet. Where pageencoding is the encoding of the JSP file itself, and ContentType's charset refers to the content encoding when the server is sent to the client.
Mentioned in the previous blog (Java Chinese garbled solution (iv)-----Java Encoding conversion process) JSP in the process of conversion to servlet is a major three-time encoding conversion process (except for database encoding conversion, page parameter input encoding conversion):
First time: Convert to. java files;
Second time: Convert to. class file;
The third time: After the business logic is processed output.
First Stage
The JVM compiles the JSP into a. jsp file. In this process, pageencoding plays a role, the JVM first gets the value of pageencoding, if the value exists, it is compiled with the encoding it sets, otherwise it is compiled with file.encoding encoding.
Phase II
The JVM converts. java files to. class files. This process is not related to any encoding settings, no matter what encoding format the JSP uses. After this phase, the. jsp file is converted to a. class file in a unified Unicode format.
Phase III
The background is processed by the business logic to output the resulting results to the client. In this process, the ContentType charset has been effective. If CharSet is set, the browser is decoded using the specified encoding format, otherwise it is decoded with the default iso-8859-1 encoding format.
The process is as follows:
-----Original from: http://cmsblogs.com/?p=1518, please respect the author's hard work results, reproduced the source of the explanation.
-----Personal site: http://cmsblogs.com
Java Chinese garbled solution (vii)-----JSP page encoding process