DEV Community

Cover image for Fix JSP Not Rendering in Spring Boot (MVC + IntelliJ Guide)
Mosopefoluwa Adebawojo
Mosopefoluwa Adebawojo

Posted on

Fix JSP Not Rendering in Spring Boot (MVC + IntelliJ Guide)

When I began learning Spring MVC, one of the hurdles I encountered was rendering .jsp (Java Server Pages) in a Spring Boot project using IntelliJ IDEA Community Edition. Unlike other IDEs that may offer built-in support for enterprise features like JSP rendering, the Community Edition requires some extra configuration.

After countless attempts and piecing together various resources, I finally figured out a working solution, and I’m here to share it with you in a step-by-step guide.

✅ Step 1: Create a New Maven Web Project

  • Open IntelliJ IDEA Community Edition
  • Create a new Project
  • Select Maven Archetype (from the left corner)

New project window in IntelliJ

  • Name your project – e.g., GetJSPWorking

New project window in IntelliJ

  • Choose Maven as your build tool (if not already selected)
  • Select the archetype: maven-archetype-webapp

Screenshot of the various archetype options in IntelliJ

  • Click Create

At this point, you should see the following structure:

Project Structure Screenshot

✅ Step 2: Setup the Project Structure

  • Create a directory named java inside src/main/.
  • Inside java, create your base package, e.g., com.example.

Screenshot of the created package

✅ Step 3: Configure the pom.xml File

  • Replace the default pom.xml content with the following:
<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.4.6</version>
    <relativePath/>
  </parent>

  <groupId>com.example</groupId>
  <artifactId>GetJSPWorking</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <dependencies>
    <!-- Spring Boot Web -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- JSP Support -->
    <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId>tomcat-embed-jasper</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- JSTL Support -->
    <dependency>
      <groupId>jakarta.servlet.jsp.jstl</groupId>
      <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
      <version>3.0.0</version>
    </dependency>

    <!-- Dev Tools -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <scope>runtime</scope>
      <optional>true</optional>
    </dependency>

    <!-- Testing -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <finalName>TestWebApplicationJSP</finalName>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
</project>

Enter fullscreen mode Exit fullscreen mode

NB: Don’t forget to update your groupId and artifactId to match your own.

✅ Step 4: Create the Application Entry Point

  • Inside your com.example package, create the main application class:
package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class GetJSPWorkingApplication {
    public static void main(String[] args) {
        SpringApplication.run(GetJSPWorkingApplication.class, args);
    }
}

Enter fullscreen mode Exit fullscreen mode

Screenshot of the main application in IntelliJ

✅ Step 5: Create a Controller

  • Also inside com.example, create a controller:
package com.example;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class GetJSPWorkingController {

    @RequestMapping("/get-jsp")
    public String getJsp() {
        return "index"; // Refers to index.jsp
    }
}

Enter fullscreen mode Exit fullscreen mode

Screenshot of the controller in IntelliJ

✅ Step 6: Add Your JSP File

  • Inside src/main/webapp/WEB-INF/, create a folder named jsp.
  • Inside jsp, create a file named index.jsp.
  • Paste this simple HTML code:
<html>
  <body>
    <h2>Hello JSP!</h2>
  </body>
</html>
Enter fullscreen mode Exit fullscreen mode

Screenshot of the index.jsp file on IntelliJ

✅ Step 7: Configure View Resolver

  • Create a file named application.properties inside src/main/resources/ with the following contents:
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
spring.web.resources.static-locations=classpath:/static/
Enter fullscreen mode Exit fullscreen mode

✅ Step 8: Build and Run the Application

  • Open the Maven tab in IntelliJ.

Screenshot of pointing to the mvn icon in IntelliJ

Screenshot of the icon that opens the mvn terminal

  • Run the following commands:

mvn clean install

Screenshot of the command in IntelliJ

mvn spring-boot:run

Screenshot of the command in IntelliJ

If everything was set up correctly, you should see:

Screenshot of the rendered JSP in the browser

Conclusion

Getting JSP to work with Spring Boot in IntelliJ Community Edition can feel tricky, but it’s totally doable. If you're like me and got stuck along the way, I hope this guide clears up the confusion and helps you render your JSP views without a hitch.

N.B: This setup is ideal for learning purposes. In production, it’s recommended to use Thymeleaf or another modern template engine, as JSP is gradually being phased out of modern Spring applications. However, understanding how to configure JSP is valuable for legacy systems and academic projects.

Top comments (2)

Collapse
 
chizobaonorh profile image
Chizobaonorh

beautiful read

Collapse
 
madebawojo profile image
Mosopefoluwa Adebawojo

thank you!