1. springboot下的内嵌Tomcat对jsp的解析包:
<!--引入Spring Boot内嵌的Tomcat对JSP的解析包,不加解析不了jsp页面-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
jsp解析俩包:
servlet-api、servlet-jsp;
jstl标签依赖包:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
2.在application.properties配置springMVC的视图展示为jsp:
spring.mvc.view.prefix=/WEB-INF/page/
spring.mvc.view.suffix=.jsp
3.获取basePath:= request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + requset.getContextPath();
对于request.getServerName()在反向代理中会错误的情况,处理如下:${pageContext.request.contextPath}/
4.Application.class
通过main方法启动springboot如下:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
//启动springboot程序,启动spring容器,启动内嵌的Tomcat
SpringApplication.run(Application.class, args);
}
}
<build>
<plugins>
<!-- springboot 提供的项目编译打包插件-->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugins>
<!-- resource的作用是定位打包后的资源文件位置-->
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
<resource>
<directory>src/main/webapp</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
</build>