Java Chinese garbled solution (vii)-----JSP page encoding process

Source: Internet
Author: User

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

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.