This tutorial will demonstrate how to run JSP pages in Spring Boot applications.

So you are still using JSP pages in your applications and you want to add them in your Spring Boot applications? This tutorial tells you exactly how to do that.

Let's start from the dependencies needed for this application:


As you can see we have included also the JSTL dependency if you want to use the JSTL libraries in your JSP pages.

Now, in order to configure JSP usage in your Spring Boot application, add the following configuration class in your web application:

package com.example.demo;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

public class Config implements WebMvcConfigurer {

    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {

    public ViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        return viewResolver;


Within this configuration class, we have configured:

  • The org.springframework.web.servlet.view.JstlView Class as standard View class
  • The project path where JSP pages are searched in the webapp/WEB-INF/pages folder
  • The suffix for our views to be ".jsp"

With that in place, just add JSP pages in the right project path, as in this example:

├── main
│   ├── java
│   │   └── com
│   │       └── example
│   │           └── cruddemo
│   │               ├──
│   │               ├── controllers
│   │               │   └──
│   │               ├──
│   │               ├── entities
│   │               │   └──
│   │               └── repositories
│   │                   └──
│   ├── resources
│   │   ├──
│   └── webapp
│       └── WEB-INF
│           └── pages
│               ├── hello.jsp
│               └── index.jsp

Now you can call your JSP pages either directly from the root Web context (ex. http://localhost:8080/index.jsp), or you can also reference them from a Controller:

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ModelAndView listAction() {

        List<String> data = new ArrayList<>();

        ModelAndView mv = new ModelAndView();

        mv.addObject("data", data);

        return mv;


In the latter example, the JSP page will be dispatched from the REST Endpoint, passing an Iterable List into it.

That's all. We have just demonstrated how to use JSP pages in a Spring Boot application.

FREE WildFly Application Server - JBoss - Quarkus - Drools Tutorials