Spring Boot
JSP
web application
rendering issue
troubleshooting

JSP file not rendering in Spring Boot web application

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

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.prefix and spring.mvc.view.suffix'

A minimal Maven setup looks like this:

xml
1<packaging>war</packaging>
2
3<dependencies>
4    <dependency>
5        <groupId>org.springframework.boot</groupId>
6        <artifactId>spring-boot-starter-web</artifactId>
7    </dependency>
8    <dependency>
9        <groupId>org.apache.tomcat.embed</groupId>
10        <artifactId>tomcat-embed-jasper</artifactId>
11    </dependency>
12    <dependency>
13        <groupId>org.glassfish.web</groupId>
14        <artifactId>jakarta.servlet.jsp.jstl</artifactId>
15    </dependency>
16</dependencies>

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:

text
src/main/webapp/WEB-INF/jsp/
  home.jsp

Then configure the resolver in application.properties:

properties
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

And return the logical view name from a controller:

java
1import org.springframework.stereotype.Controller;
2import org.springframework.ui.Model;
3import org.springframework.web.bind.annotation.GetMapping;
4
5@Controller
6public class HomeController {
7
8    @GetMapping("/")
9    public String home(Model model) {
10        model.addAttribute("message", "JSP rendering works");
11        return "home";
12    }
13}

Example home.jsp:

jsp
1<%@ page contentType="text/html;charset=UTF-8" %>
2<html>
3<body>
4    <h1>${message}</h1>
5</body>
6</html>

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 @ResponseBody or 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:

java
1import org.springframework.boot.builder.SpringApplicationBuilder;
2import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
3
4public class ServletInitializer extends SpringBootServletInitializer {
5    @Override
6    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
7        return application.sources(Application.class);
8    }
9}

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-jasper and JSTL support
  • Place JSP files under src/main/webapp/WEB-INF/jsp/
  • Configure spring.mvc.view.prefix and spring.mvc.view.suffix
  • Use @Controller and return logical view names such as "home"

Related reading
Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.