Created
April 6, 2017 01:19
-
-
Save Rotceh/a6dccd8f492a15518005ab9755f3d713 to your computer and use it in GitHub Desktop.
Include的時機
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 方法一 | |
| <jsp:include page="網頁名稱"> 或 | |
| <jsp:include page="網頁名稱"> | |
| <jsp:param name="參數1" value="值1" /> | |
| <jsp:param name="參數2" value="值2" /> | |
| ..... | |
| <jsp:include/> | |
| 此為JSP的Action,因此適用於不同page 間的控制權轉移,並且可以允許參數的傳入。 | |
| 例如希望能在原A page 執行到一半,include 另一個B page的程式來執行(將程式的執行權轉 | |
| 移到B page),待B page 執行完畢後,再回到A page 執行末完的作業。此時就必需使用Action | |
| 的方式。 | |
| ex: | |
| <jsp:include page=“login.asp” flush=“true”> | |
| <jsp:param name=“ID” value=“james” /> | |
| <jsp:param name=“password” value=“11111”/> | |
| </jsp:include> | |
| 方法二 | |
| <%@ include file=“fileURL” %> | |
| 此為JSP的Directive ,因此不能像Action的方式那樣可以轉移控制權。所以一樣的程式若採用 | |
| 此方法會變成=>原A page 執行到一半,include 另一個B page的程式來執行(B page 執行完畢 | |
| 傳回執行結果,也就是out.println();),待B page 執行完畢後,再回到A page 執行末完的作業。 | |
| 若只想利用include得到一個“執行結果”或是“靜態資料”建議使用Directive 方式 | |
| 若是想在include 的page 也能動態地做像是“forward”的動作或是能接受參數。建議使用Action 方式 | |
| 需注意的是:若你在page A 宣告了一個變數 z ,在 page B 亦有一個變數 z 此時 執行時將會產生錯誤。 | |
| 兩種include差異為Aciton方法是執行時期的引入處理,關係著兩個以上的JSP 物件,而 Directive方式是 | |
| 編譯時期的處理,只跟一個JSP 物件有關。 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment