Monolithic Architecture: Frontend and Backend in the Same Layer
1. Add View Layer
Inside your src/main folder, create the following structure:
2. Configure View Resolver
In application.properties, tell Spring where to look for JSP files:
So, if a controller returns "index", Spring looks for /WEB-INF/view/index.jsp.
3. Implement MVC Architecture
- Controller : handles request
- View : JSP page for UI
- Model : data passed between controller and view
4. Add Tomcat JSP Support
- By default, embedded Tomcat in Spring Boot does not support JSP.
so add dependency ,also need JSTL (Java Standard Tag Library):
<!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>11.0.7</version>
</dependency>
<!-- JSTL Support -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>