<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 一、集成jsp spring-boot-starter-web 包依賴了 spring-boot-starter-tomcat 不需要再單獨配置。 引入 jstl 和內嵌的 tomcat,jstl 是一個 JSP 標簽集合,它封裝了 JSP 應用的通用核心功能。 tomcat-embed-jasper 主要用來支持 JSP 的解析和運行。 ~~~ <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- spring boot 內置tomcat jsp支持 --> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> <!--jsp頁面使用jstl標簽--> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> ~~~ spring.mvc.view.prefix 指明 jsp 文件在 webapp 下的哪個目錄 spring.mvc.view.suffix 指明 jsp 以什么樣的后綴結尾 ~~~ spring: mvc: view: suffix: .jsp prefix: /WEB-INF/jsp/ debug: true ~~~ ## 二、目錄結構 這個目錄結構和配置文件一一對應,一定不要放錯了。 ![](https://box.kancloud.cn/a48d56d075ab8d320e3c7ce08640dd33_451x421.png) * 靜態資源,如:圖片放在resources/static目錄下面 * jsp文件放在webapp.WEB-INF.jsp的下面 ## 三、代碼測試 ~~~ @Controller @RequestMapping("/template") public class TemplateController { @Resource(name="articleMybatisRestServiceImpl") ArticleRestService articleRestService; @GetMapping("/jsp") public String index(String name, Model model) { List<ArticleVO> articles = articleRestService.getAll(); model.addAttribute("articles", articles); //模版名稱,實際的目錄為:src/main/webapp/WEB-INF/jsp/jsptemp.jsp return "jsptemp"; } } ~~~ jsptemp.jsp ~~~ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <table class=""> <tr> <td>作者</td> <td>教程名稱</td> <td>內容</td> </tr> <c:forEach var="article" items="${articles}"> <tr class="text-info"> <td>${article.author}</td> <td>${article.title}</td> <td>${article.content}</td> </tr> </c:forEach> </table> <img src="/image/jsp.png"> </body> </html> ~~~ **注意img標簽的靜態資源引用路徑與實際存放路徑之間的關系。** ![](https://box.kancloud.cn/3f307d7ab5b4632ee01b50fc43d2280b_769x737.png)\] ## 四、運行方法測試 因為jsp對jar運行的方式支持不好,所以要一一進行測試: 1. 使用IDEA啟動類啟動測試,沒有問題 2. 使用`spring-boot:run -f pom.xml`測試,沒有問題 3. 打成jar包通過`java -jar`方式運行,頁面報錯 4. 打成war包,運行于外置的tomcat,沒有問題(后面章節會為大家講解如何打war包) 所以,無法用jar包的形式運行jsp應用。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看