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
- 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
- Create webApp under SRC /main/
- 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
-
Launched directly from the IDE, the page is accessible
-
Start directly from the project directory
mvn clean spring-boot:run
Copy the code
- 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
- It is also accessible as a WAR package and deployed to external Tomcat