Java 我的项目可以';找不到jsp文件,我认为问题出在application.properties文件中,但不知道如何修复它
我的项目找不到jsp文件。我尝试将application.properties添加到这些行中,但这不起作用Java 我的项目可以';找不到jsp文件,我认为问题出在application.properties文件中,但不知道如何修复它,java,spring,spring-boot,jsp,Java,Spring,Spring Boot,Jsp,我的项目找不到jsp文件。我尝试将application.properties添加到这些行中,但这不起作用 spring.view.prefix=/templates/ spring.view.suffix=.jsp 当我的控制器返回html页面时,一切都正常,但这不适用于jsp 这是我的application.properties spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver sp
spring.view.prefix=/templates/
spring.view.suffix=.jsp
当我的控制器返回html页面时,一切都正常,但这不适用于jsp
这是我的application.properties
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://localhost\\SQLEXPRESS:1433;databaseName=AdminToolWeb
spring.datasource.username=mssqllogin
spring.datasource.password=mssqllogin$
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql = true
spring.view.prefix=/templates/
spring.view.suffix=.jsp
这些是我在项目中的文件。我尝试调用Movie.jsp错误是
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [Movies], template might not exist or might not be accessible by any of the configured Template Resolvers
at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1370) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1116) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:998) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:890) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
这是我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zetcode</groupId>
<artifactId>SpringBootSubmitFormEx</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
4.0.0
com.zetcode
SpringBootSubmitFormEx
1.0-快照
罐子
UTF-8
11
11
org.springframework.boot
spring启动程序父级
2.1.0.1发布
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧启动装置
org.springframework
spring上下文
5.1.2.1发布
org.springframework
SpringJDBC
5.1.2.1发布
com.microsoft.sqlserver
mssql jdbc
6.1.0.jre8
javax.servlet
jstl
org.apache.tomcat.embed
汤姆卡特·贾斯珀
假如
org.springframework.boot
springbootmaven插件
您似乎仍然使用Thymeleaf作为模板引擎。要使用JSP模板,您需要添加tomcat-embed-japser
作为依赖项:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
更新: 在查看了存储库之后,发现pom.xml中仍然存在Thymeleaf依赖项,因此类路径上仍然存在Thymeleaf依赖项,这导致了JSP模板的问题 我创建了一个解决这个问题的方法,并按照这个答案中的描述配置您的项目,因为您显然希望同时使用JSP和Thymeleaf模板
然而,除非有很好的理由使用多个模板引擎,否则我建议只使用一个模板引擎。Thymeleaf是Spring Boot的一个合理默认值,应该有一个很好的理由偏离这个默认值!使用多模板引擎是一个非标准的用例,可能会在将来导致问题(例如Spring更新等)我认为您忘记了
.mvc。
部分,这些属性应该是:
spring.mvc.view.prefix = /templates/
spring.mvc.view.suffix = .jsp
不工作,给我同样的错误不工作,给我同样的错误error@SvetoslavPanteleev我更新了我的答案。请再试一次。我没有这样的类,但我创建了它。具体在哪里以及如何使用它。我必须在Application.java中使用它吗。我将为我的新配置文件和application.java文件添加图像-新配置文件-application.java您可以直接在
应用程序类中添加图像,并且再次不要显示该文件,您是否希望向您发送指向该项目的github链接以帮助我,因为第五天我无法修复它,但我必须继续努力,因为这是我的毕业设计。如果您能帮助我,我将非常感激。它看起来像是您的JSP和Thymeleaf混合模板。我不认为这只适用于基于属性的配置。也许看看这个问题,jsp只在war文件和WEB-INF文件夹中工作,而不是在类路径中。
spring.mvc.view.prefix = /templates/
spring.mvc.view.suffix = .jsp