DEV Community

Chanbong Park
Chanbong Park

Posted on

Serving Static and JSP Resources in Spring Boot: A Guide for Legacy Integration

If you’re modernizing a legacy Java application, chances are you’re dealing with JSP files. In this post, we’ll walk through how to configure a Spring Boot application to serve both static resources and dynamic JSP pages — a common need when migrating or integrating legacy systems.

This article is based on the open-source project spring-webserver-demo, which provides a simple yet effective example.


Why JSP in 2025?

Although modern web applications typically use frontend frameworks like React or Vue, many enterprise systems still rely heavily on JSP. Being able to reuse those JSP files in a Spring Boot environment allows teams to:

  • Gradually migrate to newer tech stacks
  • Maintain and extend existing features
  • Avoid rewriting large volumes of legacy code

Project Overview

This demo shows how to:

  • Serve static content such as HTML, CSS, and JS from the /static directory
  • Render JSP pages from /WEB-INF/jsp for dynamic content
  • Configure Spring Boot to support JSP (not enabled by default)

GitHub repository: siprikorea/spring-webserver-demo


Project Structure

spring-webserver-demo/
├── src/
│   ├── main/
│   │   ├── java/com/siprikorea//webserver/
│   │   │   └── JspController.java
│   │   └── webapp/WEB-INF/jsp/
│   │       └── index.jsp
│   └── resources/static/
│       └── index.html
├── build.gradle
└── application.yml
Enter fullscreen mode Exit fullscreen mode

Configuring JSP in Spring Boot

Spring Boot does not support JSP by default, so a few adjustments are needed.

application.yml

spring:
  mvc:
    view:
      prefix: /WEB-INF/jsp/
      suffix: .jsp
Enter fullscreen mode Exit fullscreen mode

Required Dependencies (Gradle)

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    providedRuntime 'org.apache.tomcat.embed:tomcat-embed-jasper'
    compileOnly 'javax.servlet:javax.servlet-api:4.0.1'
}
Enter fullscreen mode Exit fullscreen mode
  • tomcat-embed-jasper is needed to compile and render JSP
  • javax.servlet-api is provided at runtime by the servlet container

JSP File Location

Make sure JSP files are placed in:

src/main/webapp/WEB-INF/jsp/
Enter fullscreen mode Exit fullscreen mode

This is essential because JSPs are handled by the servlet engine, not Spring’s default resource resolvers.


How to Run the Demo

Clone the project:

git clone https://github.com/siprikorea/spring-webserver-demo.git
cd spring-webserver-demo
./gradlew bootRun
Enter fullscreen mode Exit fullscreen mode

Once running, the server will be available at http://localhost:8080.


Testing the Application

Static Resource

Access http://localhost:8080/index.html
→ This should display a static HTML page located in resources/static.

Screenshot of a static HTML page served from Spring Boot’s /static directory showing a simple “Hello from static page” message.

JSP Page

Access http://localhost:8080/jsp/time
→ This will render time.jsp from WEB-INF/jsp via Spring MVC.

Screenshot of a JSP page rendering the current server time dynamically using Java code in a Spring Boot application.


When to Use This Setup

This approach is ideal when:

  • You’re migrating from a legacy system that uses JSP
  • You want to reuse JSPs without rewriting them immediately
  • You’re maintaining existing features while modernizing incrementally

Conclusion

Spring Boot doesn’t support JSP out of the box, but with a few configurations, it’s completely possible to serve both static and JSP-based dynamic content. This allows teams to modernize Java web applications step by step without sacrificing stability or increasing risk.

For the full working example, check out the repository:
👉 GitHub - siprikorea/spring-webserver-demo

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed
  • 2:34 --only-changed
  • 4:27 --repeat-each
  • 5:15 --forbid-only
  • 5:51 --ui --headed --workers 1

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

Watch Full Video 📹️

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay