Issue
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Apr 26 16:10:15 IRDT 2022 There was an unexpected error (type=Not Found, status=404). JSP file [/WEB-INF/jsp/home.jsp] not found
I have added the prefix and sufix into my application.properties:
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
This is my controller class:
@Controller
@RequestMapping("/")
public class HomeController {
@GetMapping("/")
public String index(){
return "home";
}
}
and i have 1 warning in controller class :
Cannot resolve MVC view 'home'
My Application class:
@SpringBootApplication
public class OnlineShopApplication {
public static void main(String[] args) {
SpringApplication.run(OnlineShopApplication.class, args);
}}
And the 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>
Solution
When I opened the project, I opened the folder that contained the project, which was one roll higher than the main project folder.
Answered By - Ali Bazargani
Answer Checked By - Marilyn (JavaFixing Volunteer)