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

Spring Boot项目JSP页面404未找到问题排查与解决

Troubleshooting the HTTP 404 Error in Your Spring Boot Project

Hey Ivan, let's break down why you're seeing that 404 "Page Not Found" error and how to fix it. From your project details, here are the key issues to address:

1. Incorrect JSP File Location

Spring Boot has strict conventions for where JSP files should live. By default, it looks for JSPs in src/main/webapp/WEB-INF/jsp/. If your login.jsp is placed elsewhere (like directly in src/main/webapp or another folder), Spring won't be able to locate it.

Fix:

  • Move your login.jsp to the src/main/webapp/WEB-INF/jsp/ directory (create the folders if they don't exist).
  • Alternatively, if you want to use a custom location, add these properties to your application.properties file to configure the view resolver:
    spring.mvc.view.prefix=/your/custom/path/
    spring.mvc.view.suffix=.jsp
    

2. Wrong Scope for tomcat-embed-jasper Dependency

Your pom.xml sets the tomcat-embed-jasper dependency's scope to provided. When you run your Spring Boot app as an executable JAR (which is the default for your project setup), dependencies marked as provided aren't included in the final JAR. This means the JSP rendering engine isn't available at runtime, leading to a 404.

Fix:
Change the scope of the tomcat-embed-jasper dependency from provided to compile:

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>compile</scope>
</dependency>

3. Verify Controller Package Structure (Quick Check)

Make sure your LoginController is in the same package or a sub-package of your WcApplication class. For example, if WcApplication is in com.wc, the controller should be in com.wc or com.wc.controllers—Spring Boot automatically scans components in these locations. From your code, this seems correct, but it's worth double-checking to rule out component scanning issues.

Final Steps to Test

After making these changes:

  • Stop your running application.
  • Run mvn clean install to rebuild the project.
  • Start the app again with mvn spring-boot:run or by running the JAR file.
  • Visit http://localhost:8080/ or http://localhost:8080/login—you should see the "hello" text from your login.jsp now.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 04:20:57