Spring Boot JSP页面找不到。

4
在我的Spring Boot应用中,我从Thymeleaf切换到JSP,在本地电脑上正常工作,但是当我上传到Heroku服务器时,出现以下错误:There was an unexpected error (type=Not Found, status=404). /WEB-INF/jsp/home.jsp 它的jar已打包好,如果在本地可以运行但在Heroku服务器上无法运行,这代表什么?
编辑,项目结构: enter image description here

你能分享一下你的文件夹结构吗,以显示你将JSP保存在哪里? - Jos
1个回答

11

尝试将以下代码添加到 pom.xml 文件中:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>

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

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>

and adding this to application.properties:

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

并将JSP文件移动到src/main/webapp/WEB-INF/jsp目录下。

将JSP文件移动到src/main/webapp/WEB-INF/jsp解决了问题。非常感谢。 - Weras Adve

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接