JSP file not rendering in Spring Boot web application
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
If a Spring Boot controller returns a view name and the browser shows a 404, raw JSP text, or a blank page, the problem is usually configuration rather than the controller itself. JSP support in Spring Boot is much stricter than static resources or template engines such as Thymeleaf.
Check the Rendering Model First
JSP only works with the servlet stack. If the application uses Spring WebFlux, JSP is the wrong view technology. Even on Spring MVC, Spring Boot requires the right container support and the correct view location.
A working baseline usually has these pieces:
- '
spring-boot-starter-web' - '
tomcat-embed-jasper' - a JSTL implementation
- JSP files under
src/main/webapp/WEB-INF/jsp/ - '
spring.mvc.view.prefixandspring.mvc.view.suffix'
A minimal Maven setup looks like this:
Using war packaging avoids the most common executable-jar JSP limitations. If you are starting a new app, Thymeleaf is simpler. If you must keep JSP, keep the setup conventional.
Put the Files in the Right Place
Spring Boot does not scan arbitrary folders for JSP files. Put them under WEB-INF so they are resolved by the view resolver and cannot be requested directly.
Directory layout:
Then configure the resolver in application.properties:
And return the logical view name from a controller:
Example home.jsp:
If the controller returns "home", Spring resolves it to /WEB-INF/jsp/home.jsp.
Confirm the Application Type
Several rendering issues come from the wrong dependencies rather than the JSP file itself. Check these cases:
- You accidentally included reactive dependencies and built a WebFlux app.
- You placed JSP files under
src/main/resources/templates/, which is for template engines such as Thymeleaf, not JSP. - You return
@ResponseBodyor use@RestController, which sends text directly instead of resolving a view.
For JSP rendering, the controller class should usually be annotated with @Controller, not @RestController.
Packaging and Deployment Notes
JSP support is more fragile with embedded containers than plain HTML templates. If the app works in one environment and not another, packaging is often the difference.
A safer servlet deployment looks like this:
That setup helps when deploying the application as a war file to Tomcat.
Common Pitfalls
The first pitfall is using @RestController. That bypasses view resolution completely. If you want JSP rendering, use @Controller.
The second is missing tomcat-embed-jasper or JSTL dependencies. Without them, JSP compilation fails or the page never resolves.
The third is using the wrong folder. A JSP under src/main/resources/static/ is treated as a static file, not a server-rendered view.
Another issue is returning the physical file name instead of the logical view name. Return "home", not "home.jsp", when prefix and suffix are configured.
Finally, if the project is new and you are free to choose, do not ignore the maintenance cost of JSP. Spring Boot works more naturally with Thymeleaf or another template engine designed for current Boot conventions.
Summary
- JSP rendering in Spring Boot requires Spring MVC, not WebFlux
- Add
tomcat-embed-jasperand JSTL support - Place JSP files under
src/main/webapp/WEB-INF/jsp/ - Configure
spring.mvc.view.prefixandspring.mvc.view.suffix - Use
@Controllerand return logical view names such as"home"

