Maven projects integrate JSPS

Note: Spring official does not recommend using JSP, recommended to use Thymeleaf, Freemaker, Velocity and other module engines. But since the previous project still had a lot of JSP pages, it took a lot of time to rewrite them all. It is recommended that you have a choice or not to use JSP

The consolidation process

  1. Pom.xml adds the dependencies required by JSPS
<! <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed </artifactId> </artifactId> </artifactId> </artifactId> </artifactId> </artifactId> </artifactId> </artifactId> </artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency>Copy the code
  1. Create webApp under SRC /main/

  1. Add the following properties to the application.properties file under SRC /main/resources:
#jsp config
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
Copy the code

Packaging start

Springboot integrated JSP into a JAR package, and in accordance with the Java -jar xxx.jar mode to start, access to the page will always prompt 404, need to use other methods to start

  1. Launched directly from the IDE, the page is accessible

  2. Start directly from the project directory

mvn clean spring-boot:run
Copy the code
  1. You can also access the page by packaging it as a war package and launching it with a Java-jar
java -jar xxx.war
Copy the code
  1. It is also accessible as a WAR package and deployed to external Tomcat