小編給大家分享一下圖解在Spring Boot中使用JSP頁面的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!
一、創建webapp目錄
在src/main下創建webapp目錄,用于存放jsp文件。這就是一個普通的目錄,無需執行Mark Directory As
二、創建jsp
1、指定web資源目錄
在spring boot工程中若要創建jsp文件,一般是需要在src/main下創建webapp目錄,然后在該目錄下創建jsp文件。但通過Alt + Insert發現沒有創建jsp文件的選項。此時,需要打開Project Structrue窗口,將webapp目錄指定為web資源目錄,然后才可以創建jsp文件。
指定后便可看到下面的窗口情況。
此時,便可在webapp中找到jsp的創建選項了。
2、創建index.jsp頁面與welcome.jsp頁面
三、添加jasper依賴
在pom中添加一個Tomcat內嵌的jsp引擎jasper依賴。
<dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency>
四、注冊資源目錄
在pom文件中將webapp目錄注冊為資源目錄
<build> <resources> <!--注冊webapp目錄為資源目錄--> <resource> <directory>src/main/webapp</directory> <targetPath>META-INF/resources</targetPath> <includes> <include>**/*.*</include> </includes> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
不過,我們一般會添加兩個資源目錄:
<resources> <!--注冊Dao包目錄下Mybatis映射文件資源目錄--> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> <!--注冊webapp目錄為資源目錄--> <resource> <directory>src/main/webapp</directory> <targetPath>META-INF/resources</targetPath> <includes> <include>**/*.*</include> </includes> </resource> </resources>
四、創建Controller
五、邏輯視圖配置
六、訪問
看完了這篇文章,相信你對圖解在Spring Boot中使用JSP頁面的方法有了一定的了解,想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。