对<%@ include file ="使用URL模式..."%> [英] Use a URL Pattern for <%@include file=" ..."%>

查看:122
本文介绍了对<%@ include file ="使用URL模式..."%>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在主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>

  • Prelude会添加在开头.
  • 在末尾添加
  • Coda.
    • Prelude is added in the beginning.
    • Coda is added at the end.
    • 以下是一些教程:

      定义隐式包含

      这篇关于对&lt;%@ include file =&quot;使用URL模式...&quot;%&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆