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.