Chapter 2: Web App Architecture and Mini MVC
What is the minimal runnable Java program? Most people probably are able write a simple Hello World
application in handwritten code. Is there a main()
method, right? It is the entry point of a program. Interestingly, servlets don't have a main()
method. They’re under the control of another Java application called a Container
.
We have briefly mentioned the container in Section 1.1, which is the referencing runtime in Jakarta EE, and Tomcat is an example of a container. To be specific, Tomcat is an Application Server which can also be used as a Web Server. It may be a little obscure for beginners to distinguish between server and container.
- Server, commonly used in our daily language, mainly refers to web server (i.e., HTTP server). It is capable of receiving HTTP requests and sending HTTP responses.
- Container, mainly in Jakarta EE context, refers to the runtime for servlets, JSP, EJBs, etc.
When your server gets a request for a servlet (as opposed to, say, a plain old static HTML page[1]), the server hands the request not to the servlet itself, but to the container, in which the servlet is deployed. It is the container that gives the servlet the HTTP request and response, and it's the container that calls the servlet's methods (like doPost()
and doGet()
).
In this chapter, we will discuss the web app architecture in a high-level overview, and then introduce MVC, a useful and well-tested model when developing user interface related applications.
We will also have a taste of CSS and modern web UI framework, and learn to how to beautify the bare web page.
[1] In real world settings, people tend to use other application servers (e.g., NGINX) to send static files like images (.jpg, .png, .gif), stylesheets (.css) and JavaScript (.js) directly for better performance.