控制权如何从Web服务器转移到Servlet容器

发布于 2024-12-09 18:27:41 字数 185 浏览 2 评论 0原文

引用 Java Servlet API 规范:“客户端(例如 Web 浏览器)访问 Web 服务器并发出 HTTP 请求。该请求由 Web 服务器接收并传递给 servlet 容器。”

谁能详细说明这个控制到底是如何传递的(从 Web 服务器到 Servlet 容器)?它是否使用某种 HTTP 连接器(例如 Apache Coyote)?

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 elaborate on how exactly this control is passed( from Web server to Servlet Container)?Does it use HTTP connectors of some kind like Apache Coyote?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

像你 2024-12-16 18:27:41

实现细节取决于服务器到服务器。 Http Connector 架构是 Apache Tomcat 内部使用的架构。
Web 服务器只不过是一个 Java 应用程序,它在端口上打开套接字并通过 HTTP 协议 + 一些其他设施持续侦听该端口。这些其他设施包括组件生命周期管理等。
Web 服务器的基本任务是通过 http 协议侦听端口号上的请求,然后响应该请求。因此,在当今最常见的服务器中,它们通过 http 协议持续轮询端口 80。当您在端口 80 上向程序正在侦听的主机发送一些 http 请求时,侦听程序会对此做出响应。现在,在接收到请求时,服务器程序(此处正在侦听端口 80)将从其线程池中获取一个新线程,并在该线程中调用 servlet 的服务方法(如果第一个请求见 < a href="http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets4.html" rel="nofollow">此处了解更多详细信息)。


添加:

Web 服务器是运行 HTTPD 服务的计算机。当您向服务器发送请求时,服务器会拦截该请求。Web 服务器负责接收请求并生成响应。现在,服务器在其侦听的套接字上获取输入流。从这里开始,它通过将输入包装在一个新线程中来将输入委托给 servlet 容器(以便异步处理事物,并且当 servlet 在单独的线程中处理前一个请求时,Web 服务器可以处理其他 http 请求)。 Servlet 容器是 Web 服务器的一部分。 Servlet 容器是一个单独的模块;它可以在 Web 服务器中作为单个独立程序运行(tomcat 就是其中一个示例)。现在,servlet 容器实例化一个新的 servlet(如果尚未存在)并在新的子线程中调用其服务方法。 Servlet 容器将 http 请求包装在 HTTPRequest 对象中,并将其作为参数之一传递给服务方法。

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.

简单气质女生网名 2024-12-16 18:27:41

例如,如果您使用 apache + tomcat 架构,则有一个连接器协议 (AJP)。看看 mod_jk 和 mod_proxy。

当两个组件(Web服务器和容器)位于同一个软件中(tomcat可以管理直接http请求)时,我不知道内部实现。 (事实上​​,它对我来说从来没有用过。相反,AJP 连接器很常用)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文