簡體   English   中英

將JSP文件插入其他JSP文件到特定的div

[英]insert JSP file into other JSP file to specific div

那可能嗎? 例如,如果我的main.jsp只是一個包含其他JSP文件的容器/模板,則它們位於其特定的預定義位置。

類似於以下內容:

<body>
        <!-- user input -->
            <!-- Insertion point for user input template -->
            <div id="user_input">I want user_input.jsp here</div>


            <!-- Insertion point for user data template -->
            <div id="user_data"> I want user_data.jsp here</div>

    </body>

因此,如果我僅在頁面頂部添加文件user_input.jspuser_data.jsp ,例如<%@ include file="user_input.jsp" %>那么這些HTML元素將就位。 因此,在user_input.jsp中,我具有HTML輸入形式,並且希望它與<div id="user_input">完全相同。

如何實現呢?

您可以使用JSP片段(.jspf)。 可以將JSP的片段放入文件中的特定位置。

您可以使用以下命令將.jspf輸入到您的jsp文件中:

<%@ include file="/path/to/file.jspf" %>

要將您的.jsp文件轉換為.jspf,只需在末尾加一個f,然后可能需要重新格式化代碼,就像我們將其放入main.jsp中一樣 (例如:刪除導入,刪除不必要的HTML標記。 ..等等)

JSP片段只是JSP文件,但幾乎與您的.jsp文件結合在一起,因此您可能需要在main.jsp上進行任何需要的導入。

希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM