JSP page set code (go, do not know the source)

Source: Internet
Author: User

1. Pageencoding: <%@ page pageencoding= "UTF-8"%>

JSP page encoding: The encoding of the JSP file itself

2. ContentType: <%@ page contenttype= "text/html; Charset=utf-8 "%>

Web page display encoding: The encoding that the output stream of the JSP displays in the browser

3. html page charset: <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">

Web page input encoding: input box input font encoding

4. SetCharacterEncoding:request.setCharacterEncoding (), response.setcharacterencoding ()

Request flow for Web server input: Request data for the appropriate browser for Web servers

5. SetContentType:response.setContentType ()

Response flow for Web server output: Output data from the appropriate browser for Web servers

The interaction between them and the scope, as well as the order of precedence:

1. Pageencoding: Only indicates the JSP page itself encoding format, and the page display encoding is not related; When a container reads (a file) or (a database) or (a string constant), it converts to internal Unicode, and the page displays the contents of the page when the internal Unicode is converted to the encoding specified by ContentType, if the pageencoding attribute exists. Then the character encoding of the JSP page is determined by pageencoding, otherwise it is determined by the charset in the ContentType attribute, if the charset also does not exist, the JSP page character encoding method uses the default iso-8859-1.

2. ContentType: Specifies the MIME type and the character encoding when the JSP page responds. The default value for MIME type is "text/html", and the default value for character encoding is "iso-8859-1". MIME types and character encodings are separated by semicolons;

3. The relationship between Pageencoding and ContentType:

(1). Pageencoding content is only used for JSP output encoding, will not be sent out as the header; is to tell the Web server JSP page What encoded output, the response stream encoding of the Web server output;

(2). The first stage is that the JSP is compiled into. Java, which reads the JSP according to Pageencoding's settings, and the result is translated by the specified encoding scheme into a unified UTF-8 Java source code (ie. java).

(3). The second stage is compiled by Javac Java Source to Java bytecode, no matter what coding scheme is used when JSP is written. After this phase of the results are all UTF-8 encoding Java source code. Javac with UTF-8 encoding read Java source code, compiled into UTF-8 Encoding binary code (that is,. Class), which is the JVM's specification of a constant-string expression within a binary code (Java encoding).

(4). The third stage is the Java binary Code of Tomcat (or its application container) loading and executing phase two, the output results, that is, seen on the client, then hidden in phase one and phase two of the parameters ContentType play a role.

4. The same setting as the ContentType effect also has HTML page charset, response.setcharacterencoding (), Response.setcontenttype (), Response.setheader ();

Response.setcontenttype (), Response.setheader (), the best priority;

followed by response.setcharacterencoding ();

Moreover is <% @page contenttype= "text/html; CHARESET=GBK "%>;

The last is <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>

5. Web page input encoding: In the Settings page encoding <% @page contenttype= "text/html; CHARESET=GBK "%> at the same time, also specifies the page input code, if the page display is set to UTF-8, then all the user's page input will be encoded according to UTF-8; The server-side program will set the input code before reading the form input; When the form is submitted, the browser converts the form field value to the byte value corresponding to the specified character set, and then encodes the result byte according to the HTTP standard URL encoding scheme. But the page needs to tell the server how to encode the current page; Request.setcharacterencoding () , can modify the encoding of Serverlet GET request, response.setcharacterencoding (), can modify the encoding of Serverlet return result.

JSP page set code (go, do not know the source)

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.