【问题标题】:Page is not loading on spring boot页面未在弹簧启动时加载
【发布时间】:2021-01-07 14:28:17
【问题描述】:

我正在尝试构建一个 spring boot 应用程序,当我加载一个 jsp 页面时它显示 404 错误 我正在使用 jasper 加载 jsp 下面是我的代码 主文件

@SpringBootApplication
public class SpringAppApplication {

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

}

控制器文件

@Controller
public class ApplicationController {
    @RequestMapping("home")
    public String home() {
        return "index";
    }
}

属性文件

server.port=8000
spring.mvc.view.suffix=.jsp
spring.mvc.view.prefix=/WEB-INF/pages/

依赖

    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jasper -->
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jasper</artifactId>
            <version>9.0.38</version>
        </dependency>
    </dependencies>

当我运行应用程序并访问 http://localhost:8000/home 时,我会得到一个 404 如何解决这个问题?

【问题讨论】:

    标签: java spring spring-boot spring-mvc web


    【解决方案1】:

    您将WEB-INF 文件夹放在项目结构中的什么位置? WEB-INF 的正确位置是

    src/main/webapp/WEB-INF/jsp
    

    请参考这个答案https://stackoverflow.com/a/45685114/2614885

    【讨论】:

    • 我将 webapp 文件夹放在src/main/resources 现在它可以工作了,谢谢
    猜你喜欢
    • 2019-06-20
    • 2021-03-07
    • 2018-01-16
    • 2015-04-25
    • 1970-01-01
    • 2018-09-08
    • 1970-01-01
    • 2018-04-27
    • 2018-03-04
    相关资源
    最近更新 更多