开发者

How does the control get transferred from Web Server to Servlet Container

Quoting Java Servlet API Spec : "A client (e.g., a Web browser) accesses a Web server and makes an HTTP request.This request is received by the Web server and handed off to the servlet container."

Can anyone elaborat开发者_运维知识库e on how exactly this control is passed( from Web server to Servlet Container)?Does it use HTTP connectors of some kind like Apache Coyote?


The implementation detail depends on server-to-server. Http Connector architecture is what used by Apache Tomcat internally. Web server is nothing but a Java application which opens socket on a port and keeps listening on that port over HTTP protocol + Some other facilities. These some other facilities consist of things like components lifecycle management etc. Basic task of a web server is to listen for requests on a port number over http protocol and then respond to that. So in most common server available today they keep polling on port 80 over http protocol. When you send some http request on port 80 to the host where the program is listening then program listening responds to that. Now on receiving the request the server program (which is listening on port 80 here) will get a new thread from its thread pool and in that thread will call a servlet's service method (a servlet instance will be created if its the first request see here for more details).


ADDITION:

Web Server is a machine that has a HTTPD service running. When you send the request to server the server intercepts that.Web server is responsible for receiving request and generating response. Now the server gets the input stream on the socket where it was listening. From here it delegates the input to servlet container by wrapping it in a new thread (so that things get processed asynchronously and web server can process other http requests when the previous request is served in a separate thread by servlet). A Servlet Container is a part of a Web Server. A Servlet Container is a separate module; it may run within the web server as a single standalone program (tomcat is one example of it). Now servlet container instantiate a new servlet if not already there and calls its service method in a new child thread. Servlet container wraps the http request in HTTPRequest object and pass it in one of the parameters to service method.


If you're in the case of a apache + tomcat architecture for example, there is a protocol for the connectors (AJP). Have a look at mod_jk and mod_proxy.

When both components (web server and container) are in the same software (tomcat can manage direct http requests), I don't know of the inside implementation. (It was never useful for me, in fact. At the contrary, AJP connectors are commonly used)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜