Create a springboot project through maven to start accessing the jsp page and a 404 appears
Specific error reporting
project structure
First determine whether there is a problem with the application.yml configuration
server:
port: 8181
spring:
mvc:
view:
prefix: /
suffix: .jsp
The configuration is no problem, go to the next step
Since Spring Boot does not recommend the use of jsp, I simply checked the information on the Internet, which is probably
- There are two ways to package Spring Boot, one is jar package and the other is war package. These two packaging methods can be run through the java -jar xxx.jar/war command. The war package can be independently deployed in the Servlet container, such as the commonly used (Tomcat), and jsp is not supported when using the jar package.
- Self-defined error.jsp does not override Spring Boot's default error handling page
In this case, if you want to use JSP, then you package it as a war package
Import jsp related dependency coordinates
<!--添加tomcat依赖模块.-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- 添加servlet依赖模块 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!--jsp页面使用jstl标签-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- 使用jsp引擎,springboot内置tomcat没有此依赖 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
If still not resolved, OK
The package plugin version is set to 1.4.2.RELEASE, and the resource directory is configured
Indicates that when packaging, enter the configuration files in the resources directory together.
<build>
<resources>
<resource>
<directory>src/main/webapp</directory>
<!--这里必须是META-INF/resources-->
<targetPath>META-INF/resources</targetPath>
<includes>
<!--以任意开头点任意结尾的文件-->
<include>**/**</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
After the configuration is complete, reload maven, restart the project, and visit again