Stage 1: serve Home and About Us as static HTML
Learning path / Stage 1 of 37
mvn spring-boot:run. Use the port specified for this stage and stop with Ctrl+C.Start with two fixed pages. The browser requests a file and Spring Boot serves it.
Download hello-spring-simple.zip
GET / -> static/index.html -> Home page
GET /aboutus.html -> static/aboutus.html -> About Us pageThe static folder contains files served directly. index.html is the default Home page. We do not need to write a controller or use a template engine for this stage.
Try and verify: Open / and /aboutus.html. Change the Home heading, stop and restart the app, then refresh.
Open the files to study in this stage
<!doctype html>
<html lang="en">
<head><meta charset="UTF-8"><title>Home</title></head>
<body>
<h1>Hello World</h1>
<a href="/aboutus.html">About Us</a>
</body>
</html>
<!doctype html>
<html lang="en">
<head><meta charset="UTF-8"><title>About Us</title></head>
<body>
<h1>About Us</h1>
<p>This is our first Spring website.</p>
<a href="/">Home</a>
</body>
</html>
The ZIP contains every setup file and a README.html with instructions. You can run the supplied project directly.
What is already working before we write a controller?
Our Stage 1 project includes the Spring MVC web starter. When we start it, Spring Boot configures an embedded Tomcat server and the Spring MVC infrastructure, including DispatcherServlet. We did not write these classes, but our application already uses them.
Two different meanings of container
| Part | Job in this application |
|---|---|
| Spring container (application context) | Creates and manages the configured Java objects. An object managed by Spring is called a bean. DispatcherServlet is one of the beans Boot configures here. |
| Tomcat servlet container | Receives HTTP requests and runs the registered servlets. Boot registers DispatcherServlet with Tomcat so requests can reach Spring MVC. |
These containers have different responsibilities. The Spring container manages objects; Tomcat handles the servlet environment and incoming web requests. DispatcherServlet is a servlet managed as a Spring bean and registered with Tomcat. It is not itself either container.
Follow the About Us request in Stage 1
Tomcat receives the request. DispatcherServlet coordinates Spring MVC’s handling of it. Spring MVC selects its built-in static-file handler, which reads aboutus.html and writes the file content to the HTTP response. The browser displays that HTML.
We have not written a controller in Stage 1. A handler is simply the part selected to process a request; Spring supplies the static-file handler for this example. We do not need a controller or a template engine to serve these fixed files. The Home page at / uses the default index.html welcome page.
What changes in Stage 2?
In Stage 2 we add PageController. For GET /aboutus, Spring MVC selects our mapped aboutUs() method. DispatcherServlet remains the coordinator; our method decides what to do for that route. The direct /aboutus.html URL still uses static-file handling.
Remember: Boot prepares the infrastructure; Tomcat receives the request; DispatcherServlet coordinates MVC request handling; the selected handler does the work. A Spring application that only runs background tasks can have a Spring container without DispatcherServlet. Here it is present because this is a Spring Boot MVC web application.
For now, recognize these roles. We will study controller annotations in Stage 2 and object creation and injection in later stages. No extra source file is needed for this explanation.
Check: Who receives the HTTP request? Tomcat. Who coordinates MVC handling? DispatcherServlet. Did we write an About Us controller in Stage 1? No: a built-in handler serves our file.
References: Boot servlet web applications, DispatcherServlet.
After Stage 1: the Spring words to recognize
Focus: Start the server and serve a fixed HTML file.
| Term | Our concrete example | Its place in Spring |
|---|---|---|
| Spring Boot | HelloApplication starts our website. | Boot sets up and starts the Spring application and embedded server. |
| Static resource | static/index.html and static/aboutus.html are served as files. | Spring Boot provides a standard location for these files. |
| Configuration | server.port in application.properties chooses our port. | Spring Boot reads settings that control application startup. |
| Maven dependency | pom.xml includes the web starter. | Maven brings the Spring web libraries into this project. |
| Spring container | Manages the objects configured for this application, including DispatcherServlet. | Spring’s object-management system, also called the application context. |
| Tomcat servlet container | Receives a browser request and runs the registered servlet. | The embedded servlet runtime configured by Boot. |
| DispatcherServlet | Coordinates the About Us request; a built-in handler serves the HTML file. | Spring MVC’s central servlet, provided by Boot in this web application. |
You should now be able to say: Boot sets up our web application. Tomcat receives the request, DispatcherServlet coordinates it, and Spring MVC’s built-in handler serves our static HTML file.
One small check: Which file would you edit to change the port, and which file would you edit to change the Home heading?
Concepts used in this stage
Use the right column for a quick reminder, or open a concept above for its full explanation.