Simply think: Pageencoding is the encoding of the JSP file itself; ContentType's charset refers to the content encoding when the server is sent to the client. For example: pageencoding= "GBK". The meaning of this sentence is to tell the JVM that the JSP itself uses the "GBK" code, when the JSP compiled into the servlet to the JVM, the "GBK" encoding to the JSP Web source file translation into a unified UTF-8 form of Java bytecode. If not set, the JVM defaults to this encoding using ISO-8859-1. The CHARSET=GBK in contenttype refers to the output of this web file to the browser GBK. In this process, a JSP source file needs to pass through three stages, two times encoding, in order to complete a complete output. First stage: Compile the JSP into a servlet (. java) file. The instruction used is pageencoding, according to pageencoding= "xxx" instructions, find the code rules for "XXX", When the server compiles a JSP file into a. java file, it reads the JSP according to Pageencoding's settings, and the result is a translation of the specified encoding scheme into a unified UTF-8 encoded Java source code (i.e.. java).
Second stage: From the servlet file (. java) to the Java bytecode file (. Class), from UTF-8 to UTF-8. In this phase, no matter what coding scheme is used in JSP writing, the result of this stage is all UTF-8 encoding Java source code. Javac uses UTF-8 's encoding to read the Java source code, compiled into a UTF-8 encoded binary (i.e.,. Class), which is the JVM's specification of a constant number string expressed within a binary code (Java encoding). This process is determined by the internal specification of the JVM and is not under the control of the outside world.
The third stage: from the server to the browser, which is used in the process of the instruction is contenttype. Server loading and execution from the second phase generated Java binary code, the output of the results, that is, the client can see the results, in this output process, by the ContentType attribute in the charset to specify, will UTF8 form of binary code in CharSet encoding form to output. If there is no artificial setting, the default is the form of iso-8859-1.
The process of the Java Web request encoding setup once