The process of the Java Web request encoding setup once

Source: Internet
Author: User
Tags java web

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.