Servlet Source file to Class Process

Source: Internet
Author: User

Servlet Source file to Class Process

The Servlet Source file is a text file ending with ". java. This section describes the Servlet compilation process and tracks Chinese changes.

Use "javac" to compile the Servlet source file. Javac can contain the "-encoding <Compile-charset>" parameter, which means "interpreting the Serlvet source file with the encoding specified in <Compile-charset> ".

When the source file is compiled, <Compile-charset> is used to interpret all characters, including Chinese and ASCII characters. Then convert the character constant to the Unicode character, and finally convert the Unicode to UTF.

In Servlet, you can also set the CharSet of the output stream. Before outputting the result, call the setContentType method of HttpServletResponse to achieve the same effect as setting <JSP-charset> in Jsp, which is called <Servlet-charset>.

Note: three variables are mentioned in this article: <Jsp-charset>, <Compile-charset>, and <Servlet-charset>. The JSP file is only related to <Jsp-charset>, while <Compile-charset> and <Servlet-charset> are only related to Servlet.

 
 
  1. Import javax. servlet .*;
  2. Import javax. servlet. http .*;
  3. Class testServlet extends HttpServlet
  4. {
  5. Public void doGet (HttpServletRequest req, HttpServletResponse resp)
  6. Throws ServletException, java. io. IOException
  7. {
  8. Resp. setContentType ("text/html;Charset=GB2312");
  9. Java. io. PrintWriterOut=Resp. GetWriter ();
  10. Out. println ("");
  11. Out. println ("# Chinese #");
  12. Out. println ("");
  13. }
  14. }

This file is also written in UltraEdit for Windows, where the word "Chinese" is saved as "D6 D0 CE C4" GB2312 encoding ).

Start compilation. The following table lists the hexadecimal codes of the "Chinese" characters in the CLASS file when <Compile-charset> is different. <Servlet-charset> does not play any role during compilation. <Servlet-charset> only affects the output of CLASS files. In fact, <Servlet-charset> and <Compile-charset> are used together, this achieves the same effect as <JSP-charset> In the Jsp file, because <Jsp-charset> affects both compilation and CLASS file output.

The transformation process from Servlet Source file to Class in "Chinese"

Equivalent Unicode code in the Class file in the Compile-charset Servlet Source File
GB2312 D6 D0 CE C4
(GB2312) E4 B8 AD E6 96 87 (UTF) \ u4E2D \ u6587 (= "Chinese" in Unicode ")
ISO-8859-1 D6 D0 CE C4
(GB2312) C3 96 C3 90 C3 8E C3 84 (UTF) \ u00D6 \ u00D0 \ u00CE \ u00C4 (one 00 is added before D6 D0 CE C4)
No Default) D6 D0 CE C4 (GB2312) with ISO-8859-1 with ISO-8859-1

The compilation process of a common Java program is exactly the same as that of a Servlet.

Is the Chinese Representation in the CLASS file clearly revealed? OK. Let's take a look at how the CLASS outputs Chinese characters?

  1. Servlet Context range
  2. Brief Analysis on the concept of Servlet 3.0 API
  3. Servlet comments and deployment descriptors
  4. New Features of Java Servlet and Servlet 3.0
  5. Potential risks of Servlet and JSP

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.