Whitelabel 錯誤頁面 此應用程式沒有顯式映射 /error,因此您將其視為后備。
2022 年 4 月 26 日星期二 16:10:15 IRDT 出現意外錯誤(型別=未找到,狀態=404)。未找到 JSP 檔案 [/WEB-INF/jsp/home.jsp]
我在 application.properties 中添加了前綴和后綴:
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
這是我的控制器類:
@Controller
@RequestMapping("/")
public class HomeController {
@GetMapping("/")
public String index(){
return "home";
}
}
我在控制器類中有 1 個警告:
Cannot resolve MVC view 'home'
我的專案檔案夾圖片
我的應用程式類:
@SpringBootApplication
public class OnlineShopApplication {
public static void main(String[] args) {
SpringApplication.run(OnlineShopApplication.class, args);
}}
還有 home.jsp:
<h1> hello world from jsp</h1>
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.13</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>largesize.shop.app</groupId>
<artifactId>OnlineShop</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>OnlineShop</name>
<description>Online shopping web application</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</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>
uj5u.com熱心網友回復:
似乎您缺少名為home
. 您需要創建此模板并將其存盤在\src\main\resources\templates
模板是一個 html 檔案,您將從 spring 中回傳您的回應。它應該是這樣的:
project-directory
->src
->main
->java->com->...etc
->resources
->static
->templates
home.html
other_file.html
application.properties
->test
也停止使用特定版本。用這個:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
也不支持回滾到 TomCat 9,因為 10 不受支持。
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>9.0.19</version>
</dependency>
您可以從The MVN Repository獲取這些依賴項
uj5u.com熱心網友回復:
更改以下內容:
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
到:
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
uj5u.com熱心網友回復:
當我打開專案時,我打開了包含專案的檔案夾,它比主專案檔案夾高一卷。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/470603.html