Personal Understanding of encoding and decoding when the browser interacts with servlet Components

Source: Internet
Author: User

First, you must read the html file from the browser. The html file you write must be encoded in a certain character set. Therefore, when the browser reads html files into the memory, it must first decode them. I mainly decode them, and I will omit other processes ). Then the browser must have a character set encoded by itself. Then the browser reads data from the memory for encoding and then displays the page.


In this way, we assume that the page has a form with a text input box. In the text input box, enter Chinese characters such as "hello "). Click Submit. The browser receives the request assuming that the submission method is post ). The browser data encoding is transmitted to the servlet engine. Servlet Engine to decode the data, the default is the ISO-8859-1, you can use the request. setCharacterEncoding method to set. The decoded data is sent to the request. The servlet component reads "hello" from the request. Assume that the first function to be implemented is to return "hello" to the page and display it on the page. Then the servlet will establish a connection with response, encode "hello", and then pass "hello" to response. The servlet Engine reads data from response and transmits the data to the browser. I don't think we need to perform encoding or decoding. Because you have stored the "hello" encoded data in responese ),

The browser receives the data, decodes the data, reads it into the memory, then reads the memory content, encodes it, and displays it on the page.


There may be some points that you are not considering.

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.