Learn to create and configure JSP view resolver in Spring Boot 3 application which uses JSP template files to render the view layer. Also, learn to build and deploy the application and serve static content in the JSP files.
1. Project Structure
For reference, the files in this application are placed as the given structure in the image.

2. Maven
To sever an application using JSP, we need the following dependencies. Note that we are using the Jakarta Servlet API which uses the Jakarta namespace required by Spring Boot 3.
- spring-boot-starter-web
- tomcat-embed-jasper
- jakarta.servlet.jsp.jstl-api
- jakarta.servlet.jsp.jstl
Additionally, we must use the war packaging as jar packaging is not supported as discussed in the official documentation.
3. Application Setup
3.1. Extend SpringBootServletInitializer in the Application Class
The first step in producing a deployable war file is to provide a SpringBootServletInitializer
subclass and override its configure()
method. This makes use of Spring Framework’s Servlet 3.0 support and allows you to configure the application when it is launched by the Servlet container.
3.2. Web Controller
The controller class is a regular @Controller class with request mapping annotations. Please note that we should not use the @RestController annotation, by mistake.
3.3. Model and Service
For reference, we are using a simple POJO Item as model and ItemService for returning a list of items. The service returns two items. In a real application, it will connect to the database and fetch the details from the database or any other source.
4. Setting up JSP View Resolver
To resolve JSP files location and automatically configure the JSP view resolver, we can have two approaches:
4.1. Using application.properties
The following properties automatically configure the Spring MVC to serve the content from the configured location and register the JstlView class. It is a specialization of InternalResourceView for JSTL pages, i.e. JSP pages.
Once registered, every view name returned from a handler will be translated to a JSP resource (for example: “home” → “/WEB-INF/jsp/home.jsp“), using this view class to enable explicit JSTL support.
4.2. Using Java Configuration
We can configure the JSP view resolution in the Java configuration also, as follows. Do not forget to use the @EnableWebMvc which configures the other necessary beans to support a MVC application.
4.3. Serving Static Content
By default, Spring MVC serves the static files (JS, CSS etc) from the following directories:
- /src/main/resources
- /src/main/resources/static
We can configure the custom URI and directory location as follows. The following configuration will serve a file http://localhost:8080/static/css/style.css from the location /src/main/resources/static/css/style.css.
5. JSP Files
The JSP files can be placed in /webapp/WEB-INF/jsp
directory as /WEB-INF/jsp
path has been configured with the view resolver. Add the webapp directory as the resources root so its content is copied to the root directory when building the project.
6. Package and Run the Application
After the code has been created, we can package the application from the terminal:
It will create a war file in the target directory. We can run the war file in two ways:
- Using the
java -jar
command from the terminal. - Deploying in the Tomcat application server.
To run the application from the terminal, run the following command:
It will start the embedded Tomcat server and deploy the application with it.
7. Demo
After the application has been deployed, we can access a valid application URL in the browser and the JSP page will be rendered in the browser.

8. FAQs
8.1. Views are not resolved with 404 Error
In most cases, this error indicates that you are trying to run the application as embedded jar deployment or you are not using the java-jar command to run the application.
To fix this issue, you must run the application with java-jar command or deploy it inside a Tomcat server.
8.2. ClassNotFoundException: jakarta.servlet.jsp.jstl.core.Config
This error indicates that you are still using the javax.servlet:jstl
dependency. With the latest Spring Boot release, we must use the Jakarta namespaces so add the following dependency.
9. Conclusion
In this Spring Boot JSP example, we learned to serve the JSP pages in a Spring boot 3 application, configure the view resolution, and serve static content with a demo. We also learned to fix some common mistakes that developers make when serving the JSP page.
Happy Learning !!
Comments