Analysis of JSP and Servlet encoding in javaee

Source: Internet
Author: User

Encoding:

In JSP and Servlet, encoding can be set in the following aspects,

Pageencoding = "UTF-8", contenttype = "text/html; charset = UTF-8", request. setcharacterencoding ("UTF-8") and response. setcharacterencoding ("UTF-8 "),

Response. setcontenttype ("text/html; charset = UTF-8 ");

 

The first two can only be used in JSP, and the last two can be used in JSP and servlet.

JSP: pageencoding = "UTF-8" contenttype = "text/html, UTF-8"

JSP: first, the encoding method set by myeclipse is used to generate a file with the JSP extension that is saved on the local hard disk. During the first access, JSP files are compiled into files with the Java extension, and the compiled code is compiled into corresponding java files based on pageencoding = "UTF-8" in JSP, (eventually compiled into a file with the class extension) during compilation and translation into a Java file, if the encoding is different from the encoding stored in the JSP file, the encoding problem will occur (the strings defined in the JSP file will have problems, rather than the data submitted from the browser ),

 

In JSP, The contenttype = "text/html, UTF-8" command and the response. setcontenttype ("text/html; charset = UTF-
8 "); the method is the same

It is the encoding method used by the browser to respond to the server, that is, the encoding method used to unpack the data packets sent by the server. (A message header is generated when the browser sends the data packets to notify the browser of this encoding method) the browser also uses this method to package the data and send it to the server.

 

When a browser sends a data packet, should the server parse the data packet? So what is the encoding method for parsing data packets on the server? Request. setcharacterencoding () so that the server will parse the packets sent by the browser according to the specified encoding method

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.