1. Spring boot supports jsp
pom:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency>
2. Add InternalResourceViewResolver bean to the startup class so that the controller can get it back to jsp
//java project www.1b23.com @Bean public InternalResourceViewResolver setupViewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/"); resolver.setSuffix(".jsp"); return resolver; }
3. Add the ConfigurableServletWebServerFactory bean to the startup class so that the jsp file can be obtained
//java project www.1b23.com @Bean public ConfigurableServletWebServerFactory serverFactory() { ConfigurableServletWebServerFactory aFactory = new TomcatServletWebServerFactory(); aFactory.setDocumentRoot(new File("jsp server full path")); return aFactory; }
When developing locally, the serverFactory() method can directly return new TomcatServletWebServerFactory()