[Java] Servlets

A servlet is a class which responds to a particular type of network request (most commonly an HTTP request). Servlets are usually used to implement web applications.

Servlets run in a servlet container, which handles the network side (eg. parsing HTTP request, connection handling.etc). One of the best-known source servlet containers is Tomcat.

Flow of Request

  1. Client sends HTTP request to Web Server
  2. Web Server forwards HTTP request to Web Container
  3. Web Container converts request into valid request object (because servlet cannot understand HTTP; only understands objects)
  4. Web container spins a thread for each request.
  5. All the business logic goes inside doGet() and doPost() methods inside the servlets.
  6. Servlet builds a Java response object and sends it to the container. It converts that to HTTP response again and send it to the client.


Comments

Popular posts from this blog

[Redis] Redis Cluster vs Redis Sentinel

[Unit Testing] Test Doubles (Stubs, Mocks....etc)

[Node.js] Pending HTTP requests lead to unresponsive nodeJS