SpringBoot使用JSP
2020-03-01 本文已影响0人
我问你瓜保熟吗
491787.jpg
- Maven
<!-- 只能打成war包,不支持打成jar包 -->
<packaging>war</packaging>
<!--引入Spring Boot内嵌的Tomcat对JSP的解析包-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!--jsp依赖的jar包-->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlt.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<!--jstl标签依赖的jar包-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!--servlet依赖的jar包-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
- 配置
spring:
mvc:
view:
prefix: /WEB-INF/pages/
suffix: .jsp
# 或者
spring.view.prefix=/WEB-INF/views/
spring.view.suffix=.jsp
-
创建src/main/webapp/WEB-INF/views目录,JSP文件就放这里
-
jsp页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title></head>
<body>
${welcome}
</body>
- 如果找不到页面,
build
标签内添加
<resources>
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath> <!--编译后的路径:/target/META-INF/resources-->
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>