2012-06-08 62 views
0

我想向主JSP頁面添加另一個JSP頁面(例如:頁面頁面)。我想避免編寫真正的jsp頁面名稱。所以我寫了一個名字,比如說「topbanner」。 下面是它的代碼對<%@ include file =「...」%>使用URL模式

<%@include file="topbanner"%> 

真正的頁面是topheader.jsp,它位於項目
- >基於web>報頭 - > topheader.jsp

在我的部署描述符(網頁。 xml),我已經在web.xml中映射了topheader.jsp

<servlet> 
     <servlet-name>pagetop</servlet-name> 
     <jsp-file>/header/topheader.jsp</jsp-file> 
    </servlet> 
<servlet-mapping> 
     <servlet-name>pagetop</servlet-name> 
     <url-pattern>/topbanner</url-pattern> 
    </servlet-mapping> 

但是這不起作用。它會拋出異常

org.apache.jasper.JasperException: /index.jsp (line: 11, column: 1) File "/topbanner" not found 

任何人都可以告訴我問題出在哪裏以及如何使用示例代碼修復它。

編輯
我不能用<%@include file=" ..."%>的映射JSP S'

回答

1

Static <%@ ...> JSP包含給定路徑內的文本。如果您希望在頂部或底部包含另一個JSP,則應使用prelude and code

下面是示例:

<jsp-config> 
    <jsp-property-group> 
    <url-pattern>*.jsp</url-pattern> 
    <include-prelude>/header.jsp</include-prelude> 
    <include-coda>/footer.jsp</include-coda> 
    </jsp-property-group> 
</jsp-config> 
  • Prelude在開始加入。
  • Coda在最後添加。

這裏有一些教程:

+0

非常感謝。我爲使用標題和底部橫幅獲得了新的觀點。 –

+0

我試過你的code.But ID沒有工作。我創建了一個示例項目,它在web.xml中有index.jsp,footer.jsp,header.jsp和以上代碼。在jsp頁面中我也使用了'include file'。你會解釋更多嗎?(如何在jsp頁面中使用'include file')。也可以說,我只需要在一個特定的jsp頁面中包含一個jsp頁面。那我該如何使用序曲和尾聲? –

+0

它應該工作,不知道爲什麼它沒有工作。要包含在一個特定頁面中,您可以在中提供絕對路徑。像 index.jsp

相關問題