简体   繁体   English

在每个JSP中自动包含JSP

[英]Automatically include a JSP in every JSP

I would like to simplify my JSP's even further by transparently including them. 我想通过透明地包含它们来进一步简化我的JSP。 For instance, this is the line I would like to remove: 例如,这是我要删除的行:

<%@ include file="/jsp/common/include.jsp"%>

The include.jsp file basically declares all the tag libraries I am using. include.jsp文件基本上声明了我正在使用的所有标记库。 I am running this on WebSphere 6.0.2 I believe and have already tried this configuration: 我在WebSphere 6.0.2上运行它我相信并且已经尝试过这个配置:

<!--    Include this for every JSP page so we can strip an extra line from the JSP  -->
    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.htm</url-pattern>
            <!--<include-prelude>/jsp/common/include.jsp</include-prelude>-->
            <include-coda>/jsp/common/include.jsp</include-coda>
        </jsp-property-group>
    </jsp-config>

Both the include-prelude and include-coda did not work. include-preludeinclude-coda都不起作用。

I was reading that other WebSphere users were not able to get this up and running; 我读到其他WebSphere用户无法启动并运行; however, tomcat users were able to. 但是,tomcat用户能够。

The jsp-property-group was introduced in JSP 2.0 (iow Servlet 2.4). jsp-property-group是在JSP 2.0(iow Servlet 2.4)中引入的。 Websphere 6.0 is Servlet 2.3. Websphere 6.0是Servlet 2.3。

So you have 3 options: 所以你有3个选择:

  1. Forget it. 算了吧。
  2. Upgrade Websphere. 升级Websphere。
  3. Replace Websphere. 替换Websphere。

I'm not sure which version of the Servlet spec this was introduced... is it possible that Websphere's servlet container doesn't support it? 我不确定引入了哪个版本的Servlet规范...... Websphere的servlet容器是否可能不支持它?

Either way, for this sort of task there's a much nicer 3rd-party tool called SiteMesh . 无论哪种方式,对于这种任务,有一个更好的第三方工具叫做SiteMesh It allows you to compose pages in exactly the sort of way you describe, but in a very flexible way. 它允许您以您描述的方式组合页面,但是以非常灵活的方式。 Recommended. 推荐的。

您可以尝试编写一个调用的过滤器

getRequestDispatch( "path-to-jsp-to-include" ).include( req, res )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM