Tuesday, February 10, 2015

What is a Servlet Container?

Servlet container or Web container is a standalone component or the component of a web server that interacts with Java servlets. The container implements Java Servlet Specification whereas the servlet is a java class which conforms to Java Servlet Specification. Thus A web container is responsible for managing the lifecycle of servlets, mapping a URL to a particular servlet based on configuration and ensuring that the URL requester has the correct access rights.
All servlet containers must support HTTP as a protocol for requests and responses, but additional request/response-based protocols such as HTTPS (HTTP over SSL) may be supported.

In Servlet 2.4 Specification the sequence of events which will occur is given as,

1. A client (e.g., a Web browser) accesses a Web server and makes an HTTP re-
quest.
2. The request is received by the Web server and handed off to the servlet con-
tainer. The servlet container can be running in the same process as the host
Web server, in a different process on the same host, or on a different host from
the Web server for which it processes requests.
3. The servlet container determines which servlet to invoke based on the config-
uration of its servlets, and calls it with objects representing the request and re-
sponse.
4. The servlet uses the request object to find out who the remote user is, what
HTTP
POST
parameters may have been sent as part of this request, and other
relevant data. The servlet performs whatever logic it was programmed with,
and generates data to send back to the client. It sends this data back to the client
via the response object.
5. Once the servlet has finished processing the request, the servlet container en-
sures that the response is properly flushed, and returns control back to the host
Web server.

No comments:

Post a Comment