大體步驟:

(1)創(chuàng)建Maven web project;
(2)在pom.xml文件添加依賴;
(3)配置application.properties支持jsp
(4)編寫(xiě)測(cè)試Controller
(5)編寫(xiě)JSP頁(yè)面
(6)編寫(xiě)啟動(dòng)類(lèi)Application.Java
1,F(xiàn)reeMarker
2,Groovy
3,Thymeleaf (spring 官網(wǎng)使用這個(gè))
4,Velocity
5,JSP (貌似Spring Boot官方不推薦,STS創(chuàng)建的項(xiàng)目會(huì)在src/main/resources 下有個(gè)templates 目錄,這里就是讓我們放模版文件的,然后并沒(méi)有生成諸如 SpringMVC 中的webapp目錄)
不過(guò)本文還是選擇大家都熟悉的JSP來(lái)舉例,因?yàn)槭褂肑SP與默認(rèn)支持的模版需要特殊處理,所以拿來(lái)舉例更好。
(1)創(chuàng)建Maven web project
使用Eclipse新建一個(gè)Maven Web Project ,項(xiàng)目取名為:
spring-boot-jsp
(2)在pom.xml文件添加依賴
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>spring-boot-jsp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<dependencies>
<!-- web支持: 1、web mvc; 2、restful; 3、jackjson支持; 4、aop ........ -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- servlet 依賴. -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- JSTL(JSP Standard Tag Library,JSP標(biāo)準(zhǔn)標(biāo)簽庫(kù))是一個(gè)不斷完善的開(kāi)放源代碼的JSP標(biāo)簽庫(kù),是由apache的jakarta小組來(lái)維護(hù)的。JSTL只能運(yùn)行在支持JSP1.2和Servlet2.3規(guī)范的容器上,如tomcat
4.x。在JSP 2.0中也是作為標(biāo)準(zhǔn)支持的。 不然報(bào)異常信息: javax.servlet.ServletException: Circular
view path [/helloJsp]: would dispatch back to the current handler URL [/helloJsp]
again. Check your ViewResolver setup! (Hint: This may be the result of an
unspecified view, due to default view name generation.) -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- tomcat 的支持. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>spring-boot-jsp</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
新聞名稱(chēng):詳解SpringBoot添加JSP支持-創(chuàng)新互聯(lián)
文章地址:http://www.chinadenli.net/article34/poppe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、品牌網(wǎng)站制作、企業(yè)網(wǎng)站制作、服務(wù)器托管、自適應(yīng)網(wǎng)站、ChatGPT
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容