PizzaStack.github.io

HTTP/HTML

Hypertext Transfer Protocol & Hypertext Markup Language, the two main technologies for a web browser. HTML provides a structure for static content on web pages. HTML documents are organized by element tags, some with attributes. Browsers don’t display the element tags, but instead parse them to render content.

Hello there!

Google

HTTP is all about sending and receiving documents. A document is abstracted from HTTP packet that has information like metadata, contents, status codes.

JavaEE

Java Enterprise Edition, this is a community driven collection of Specifications, APIs and Frameworks which provide enterprise functionality. We will start with Java Servlets, a JavaEE API for communicating between a Java code base and HTTP.

Found in javax.servlet and javax.http the Servlet API provides a Servlet Interface which is implemented by the GenericServlet Abstract Class, then the HTTPServlet Abstract Class, and then finally allows you to extend the HTTPServlet.

In a normal servlet process:

Servlet Lifecycle

The Tomcat server will handle the control flow of your application through a servlet lifecycle process.

  1. When a request comes in, the container instantiates any appropriate servlets
  2. Once instantiated the container initializes the servlet by invoking its init() method
  3. After initialization (or existing servlet is found), the container invokes service() to process the request.
    1. public void service (ServletRequest req, ServletResponse resp) {…} ->
    2. protected void service (HttpServletRequest req, HttpServletResponse resp) {…} ->
    3. protected void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {…} //You write this
  4. Response object is returned to client
  5. When the container shuts down or needs to conserve memory or just because a servlet’s stated lifespan is reached, the container will call the destroy() method of your servlet.

tl;dr Container calls init() once, service() many times, and eventually destroy() once.

HTTP Status Codes

HTTP Methods (Verbs)