对<%@ include file ="使用URL模式..."%> [英] Use a URL Pattern for <%@include file=" ..."%>
问题描述
我想在主JSP页面上添加另一个JSP页面(例如:标头页面).我想避免写真正的jsp页面名称.因此,我写了另一个名字,比方说"topbanner". 在代码中
I want to add another JSP Page(Example: a header page) to a main JSP page. I want to avoid writing the real jsp page name. Therefore I write some another name,let's say "topbanner". Here is it in code
<%@include file="topbanner"%>
实际页面是topheader.jsp,它位于项目中
-> web-> header-> topheader.jsp
The real page is topheader.jsp and it is located in project
->web->header->topheader.jsp
在我的部署描述符(web.xml)中,我已将topheader.jsp映射到web.xml中
In my deployment descriptor (web.xml), I have mapped the topheader.jsp in web.xml
<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>
但这不起作用.引发异常
But this doesn't work. it throws exception
org.apache.jasper.JasperException: /index.jsp (line: 11, column: 1) File "/topbanner" not found
任何人都可以让我知道问题出在哪里以及如何用示例代码解决它.
Any one let me know where the problem is and how can I fix it with a sample code.
编辑
我不能对映射的jsp使用<%@include file=" ..."%>
吗?
EDIT
Can't I use <%@include file=" ..."%>
for mapped jsp s ?
推荐答案
静态<%@ ...> JSP包含给定路径内的文本.如果要在顶部或底部包含另一个JSP,则应使用prelude and code
.
Static <%@ ... > JSP includes the text inside the path given. If you are looking to include another JSP on top or bottom , you should use 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>