JSP 中操作的功能是什麼?


此操作允許您將檔案插入正在生成的頁面中。以下是語法表述:

<jsp:include page = "relative URL" flush = "true" />

include 指令不同,後者在將 JSP 頁面轉化為 servlet 時插入檔案,此操作在請求頁面時插入檔案。

下表列出了與 include 操作關聯的屬性: -

序列號。屬性和說明
1頁面
要包含頁面的相對 URL。
2重新整理
布林屬性確定所包含的資源是否在其包含前重新整理其緩衝區。

舉例

讓我們定義以下兩個檔案 (a)date.jsp(b) main.jsp,如下所示: -

以下是 date.jsp 檔案的內容: -

<p>Today's date: <%= (new java.util.Date()).toLocaleString()%></p>

以下是 main.jsp 檔案的內容: -

<html>
   <head>
      <title>The include Action Example</title>
   </head>
   <body>
      <center>
         <h2>The include action Example</h2>
         <jsp:include page = "date.jsp" flush = "true" />
      </center>
   </body>
</html>

現在,我們將所有這些檔案儲存在根目錄中,並嘗試訪問 main.jsp。您將收到以下輸出: -

include 操作示例

Today's date: 12-Sep-2010 14:54:22

更新於: 2019 年 7 月 30 日

332 次瀏覽

開啟您的 事業

完成課程並獲得認證

開始使用
廣告
© . All rights reserved.