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