Java Chinese garbled solution (7) ----- JSP page encoding process, java ----- jsp

Source: Internet
Author: User

Java Chinese garbled solution (7) ----- JSP page encoding process, java ----- jsp

We know that JSP pages need to be converted to servlet, which must be encoded during the conversion process. The following code plays a vital role in converting JSP to servlet.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="GBK" %>

The preceding Code contains two charset codes: pageEncoding and contentType. WherePageEncoding is the encoding of the jsp file, while the charset of contentType refers to the content encoding sent by the server to the client.

As mentioned in the previous blog (java Chinese garbled solution (4) ----- java coding conversion process) in the process of converting jsp to Servlet, it requires a major three-step encoding conversion process (except for database encoding conversion and page parameter input encoding conversion ):

First time: Convert to A. java file;

Second: convert to the. class file;

Third: output after business logic processing.

Stage 1

JVM compiles JSP into A. jsp file. In this process, pageEncoding plays a role. JVM first obtains the value of pageEncoding. If this value exists, it uses the encoding it sets to compile. Otherwise, file is used. encoding.

Stage 2

JVM converts a. java file to a. class file. In this process, it has nothing to do with any encoding settings. No matter what encoding format JSP adopts, it will be invalid. After this phase, the. jsp file is converted into a unified Unicode format. class file.

Stage 3

After the background is processed by the business logic, the results are output to the client. In this process, the charset of contentType plays a role. If charset is set, the browser uses the specified encoding format for decoding, otherwise it uses the default ISO-8859-1 encoding format for decoding.

The process is as follows:

----- Original from: http://cmsblogs.com /? P = 1518Please respect the author's hard work and repost the source.

----- Personal site: http://cmsblogs.com

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.