You are expected to know Servlet and Apache Tomcat before heading below content.
In Model View Controller (MVC) architecture:
- Controller (Handles Requests)
- Acts as the middleman between Model and View
- Receives HTTP requests, processes input, and calls the appropriate model logic
- Passes data to the view (powered by different view technology) to render
- Model (Data & Business Logic)
- Represents the data (like a Java class: User, Product)
- Contains business logic and rules (e.g., calculating prices, validating input)
- Communicates with the database (via DAOs or repositories)
- View (User Interface)
- Responsible for displaying data to the user
- Usually built using HTML, JSP, Thymeleaf, or another templating engine
- Should not contain business logic
You will learn more about MVC in Spring Framework. Now we have different view technologies:
JavaServer Pages (JSP)
Note
You can write Java code inside a JSP file (think of it as HTML with embedded Java code). Tomcat is a Servlet container, which means it can only run Servlets, not raw JSPs directly.
However, behind the scenes, a JSP page is automatically converted into a Servlet by Tomcat Jasper (you will need Tomcat Jasper added in the project dependency), and that Servlet is then managed and executed by Tomcat.
So, even though you wrote a
.jspfile, Tomcat turns it into a.javaservlet file, compiles it into a.class, and then executes it.
- Pros:
- Part of the Servlet spec
- Easy to integrate with Java
- Can use JSTL (tag libraries) to reduce Java code inside HTML
- Cons:
- Still mixes some Java in HTML (if not careful)
- Debugging can get messy in large apps
- Outdated in many modern setups
Thymeleaf (popular with Spring)
- Pros:
- Modern, HTML-friendly syntax (can open templates in a browser)
- No Java code inside templates
- Strong Spring Boot integration
- Great for form binding and template reuse
- Cons:
- Slight learning curve if you’re new
- Heavier than JSP in terms of configuration (but Spring Boot simplifies it)
FreeMarker
- Pros:
- Flexible and powerful templating syntax
- Popular in large enterprise applications
- Logic-free templates (separate business logic)
- Cons:
- Verbose syntax compared to Thymeleaf
- Needs configuration if you’re not using Spring Boot
Frontend frameworks with REST API (React, Vue, Angular)
- Pros:
- Total separation of concerns: frontend and backend are split
- Great user experience and interactivity
- Scalable architecture (backend = pure API)
- Cons:
- More complex project setup
- Requires JavaScript/TypeScript knowledge
- Not strictly “Java view technologies,” but common in modern apps
Conclusion
You can build your application with Servlet and Tomcat, you can use Servlets for handling requests, JSP or other templating for the view, and JDBC for database access. You could build everything from scratch:
- Routing (URL → Servlet)
- Session management
- Error handling
- Security
- Dependency injection (manually)
As your app grows, you’ll run into pain points:
- Tedious configuration (
web.xml, servlet mapping, etc.) - Manual wiring of dependencies (no dependency injection)
- Rewriting boilerplate logic over and over
- Difficult to test and maintain
- No built-in structure or conventions
- Limited support for REST APIs out-of-the-box
This is why we need Spring Boot, which is like getting a ready-made car chassis with a plug-and-play engine, so you can focus on driving (business logic) instead of building everything yourself.
Back to parent page: Java Enterprise Edition (Java EE)