Siege Lion on the road (restaurant) how Tomcat works (a) simple Web server

Source: Internet
Author: User
There are three classes in total for this section: Request\response\httpserver---User.dir The purpose of this section is to implement simple Web server access to static files.    Need to understand the request header, the format of the request body, otherwise there is no way to parse. 1, Request: The Main method is the parse, the main logic of the method is to parse the socket inputstream, read the input stream, parse out the request to access the address URI, such as:/index.jsp parsing the URI, is the standard format for HTTP request parsing        : get/articles/news/today.asp http/1.1 2, Response: This class constructor requires the request object for the purpose of obtaining the file path to be accessed through Request.geturi ().    The stitching path finds the actual file and then writes the file as a stream through the outputstream of the socket.   3, Httpserver: Create a ServerSocket, responsible for listening to the socket request, get the socket object, and then generate the request and response object, to the socket side to return data. Start by Httpserver#main method, Access http://localhost:8080/index.jsp;

Siege Lion on the road (restaurant) how Tomcat works (a) simple Web server

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: 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.