HTTP - Servers and Protocols
Notes on HTTP2 and web server threading models. Covers servlets, web server/container architecture (Jetty), HTTP2, HTTP streams (prioritization, flow control) and SSE.

What are Servlets?
A server side Java API/programming model for handling HTTP requests and sending back responses. A lot Java based frameworks use Servlets under the hood.
A Servlet container is created to encapsulate Servlets and decouple them from the web server implementation - you can attach a servlet container to a web server.
You can annotate a class with @WebServlet (jakarta.servlet.annotation) to specify the path. Here are some examples for a GET and a POST:
GET:
@WebServlet("/product")
public class ProductServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// do stuff
}
}
POST:
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// do stuff
}
}
In some implementations, there is some delegation involved in the implementation, for example:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
ServletContext
Created at startup, used to register Servlets, Filters and Listeners. Annotation configurable init() method called on startup.
This context is shared across all requests and all sessions.
Requests and Responses
The Servlet container is responsible for the instantiation/construction (there is also reuse of requests and responses) of HttpServletRequest and HttpServletResponse objects and passing them through the filter chain via doFilter().
The service() method is called for Servlets which determines the specific do.*() method to call based on the HTTP verb.
Conceptually only for the lifetime of the request and the completion of the response.
HTTPSession
Shared across all requests in the same session (see HTTP protocol details below). Created for the first time when a client connects/visits your page.
