Servlet/JSP Container development Note 1

Source: Internet
Author: User

During the Spring Festival holiday in 2004, I suddenly wanted to develop a Servlert/JSP (preferred for SUN Enterprise Applications) Container similar to tomcat (a very useful jsp running platform, implement the Servlet2.3 and jsp specifications (preferred for SUN Enterprise Applications) 1.2,
At the same time, the development process experiences and experiences are written as notes for your reference and correction by netizens and programmers. You are welcome to provide valuable comments. After the development is complete, all the development documents and
Share the source code with you. Thank you!


ESoftWind
2004/2/4

ServletInputStream

The HTTP/1.1 request packet consists of a RequestLine, multiple request headers, and BodyContent. The request Header and data content are separated, the Cotent-Length attribute of the Request Header describes the Length of BodyContent. If the request header does not contain the Content-Length attribute, the request package does not contain BodyContent.

ServletInputStream implements reading BodyContent input stream

Implementation of the read method:

-1 must be returned to indicate the end Of the stream. The input stream (bottom layer) from the Socket at the underlying layer will never return-1 unless the Socket is closed on the client, if the data at the bottom flow has been read, then calling the read method at the bottom flow will cause blocking of the current thread. Therefore, if you want to rely on the base stream to return-1, it indicates that the end of ServletInputStream is not feasible.

Therefore, you can only rely on the Content-Length attribute to determine whether the stream ends. If the total amount of data read exceeds the Content-Length,-1 is returned.

For a request whose Content-Type is equal to application/x-www-form-urlencoded, the Container must read from the bottom layer to parse the request parameter. In this case, servletInputStream cannot implement the read method simply by reading the bottom-layer data (because BodyContent has been read), but can only implement the ServletInputStream by reading the data in request parameter through the cache.

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.