jsp include file(變數) 動態負載檔案

來源:互聯網
上載者:User

標籤:

include file( 變數) 動態負載檔案



      <%@include file="/includes/<%=id %>/abc.html" %>  這樣寫系統會報錯,提示找不到檔案,主要原因是<%=id %>並沒有被解析為你想要的id。

      好,我們換一種方式,使用<jsp:include page="/includes/<%=id %>/adc.html"></jsp:include>是不是可以呢。在Eclipse中<%=id %>顯示的顏色告訴我們這樣應該可以。不過,不好意思,這樣還真的不行。

      那我們再換個思路,我們把整個page後面的值當成一個變數,寫成這樣:

<%String add = "/includes/" + id+ "/abc.html"; %>
<jsp:include page="<%=add %>"></jsp:include>

 經過測試這樣是可行的。反過來你可能會想到

<%String add = "/includes/" + id+ "/abc.html"; %>
<%@include file="<%=add %>" %>

 

些是不是也可以呢,經測試,這樣還是不行。

 

下面轉自:http://hi.baidu.com/hankers/blog/item/dc1bda54489c215dd0090674.html

<%@ include file="" %>
    靜態包含檔案,即在編譯時間插入包含的檔案。file不能為一變數URL,也不可以在file 所指定的檔案後接任何參數,file 所指的路徑必須是相對於此JSP 網頁的路徑。
如果在includebydirectives.jsp中使用<%@ include file="common.jsp"%>,則會在產生的includebydirectives_jsp.java中將common.jsp的檔案包含進來。
註:在common.jsp、includebydirectives.jsp可相互引用定義的變數、方法。在common.jsp中定義的指令會合并到includebydirectives.jsp中。
<jsp:include page="" />
     動態包含檔案,即在運行時加入包含檔案的運行結果。文法:
<jsp:include page="{urlSpec | <%= expression %>}" flush="true | false " />

<jsp:include page="{urlSpec | <%= expression %>}" flush="true | false" >
<jsp:param name="PN" value="{PV | <%= expression %>}" /> *
</jsp:include>
如果在includebyaction.jsp中使用<jsp:include flush="true" page="common.jsp"></jsp:include>,則在產生的includebyaction_jsp.java中在include的地方會加入一條:
org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "common.jsp", out, true);
註:includebyaction.jsp和common.jsp是相互獨立的,includebyaction.jsp只是把common.jsp執行的結果加入。

 

更詳細的資訊請參考:http://hi.baidu.com/%D2%BB%C9%FA%CF%B7/blog/item/694657f378c5305c352accf2.html

jsp include file(變數) 動態負載檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.