You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot项目无WEB-INF文件夹?JSP存放路径及手动创建可行性咨询

Spring Boot中JSP文件的放置位置与WEB-INF文件夹的创建问题

Hey there! This is a super common question when starting out with Spring Boot and JSPs—since Spring Boot leans hard into convention over configuration, the traditional WEB-INF folder isn't included in the default project structure generated by Spring Initializr. Let's break this down clearly:

1. Where to place your JSP files

Spring Boot looks for JSPs in two standard locations by default:

  • src/main/resources/META-INF/resources/WEB-INF/jsp/
  • src/main/webapp/WEB-INF/jsp/

The second option (src/main/webapp) is the more traditional approach and what most developers use. The catch? This directory doesn't exist in the default Initializr project, so you'll need to create it manually (more on that below).

Whichever location you choose, make sure to configure your view resolver in application.properties (or application.yml) to point to the right path:

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

This tells Spring where to find your JSP files when resolving view names.

2. Can you manually create the WEB-INF folder?

Absolutely—this is not only allowed, but it's the recommended approach when working with JSPs or other traditional web resources (like tag libraries, static assets, or custom error pages). Here's how to set it up:

  1. In your project root, create the src/main/webapp directory (if it doesn't already exist)
  2. Inside webapp, create the WEB-INF subfolder
  3. Add a jsp folder inside WEB-INF and drop your JSP files there

Critical Note: Don't forget the dependencies

For JSPs to work in Spring Boot, you need to include two key dependencies in your pom.xml (Maven) or build.gradle (Gradle):

Maven:

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>

Gradle:

implementation 'javax.servlet:jstl'
providedRuntime 'org.apache.tomcat.embed:tomcat-embed-jasper'

Without these, even if your JSPs are in the right place, Spring Boot won't be able to render them.

Hope that solves your issue! If you run into any trouble getting your JSPs to load, double-check the view resolver config and dependencies first—those are the most common pain points.

内容的提问来源于stack exchange,提问作者Rajanikanta Pradhan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:49:52