简体   繁体   English

在EAR之间共享JSP

[英]Sharing JSPs between EARs

Is it possible to share JSPs between EARs, similar to the way that we can share Java files between EARs by using .jar files? 是否可以在EAR之间共享JSP,就像我们可以使用.jar文件在EAR之间共享Java文件一样?

I have a large J2EE app on JBoss with many different EARs, and they all should have the same header, footer, etc... I would rather not copy and paste these files a dozen times whenever a change needs to be made. 我在JBoss上有一个大型的J2EE应用程序,它具有许多不同的EAR,并且它们都应具有相同的页眉,页脚等。当需要进行更改时,我宁愿不复制和粘贴这些文件十多次。

Tag files can be packaged in a jar. 标记文件可以包装在罐子中。

They are JSP files with a ".tag" extension. 它们是带有“ .tag”扩展名的JSP文件。 They can be parameterized. 可以对其进行参数化。

我从未尝试过,但从逻辑上讲,通过将所有JSP放入一个公共文件夹中,您可以很好地做到这一点

I think of it as accessing a different servlet context from the one you are in. Something like 我认为它是与您所处的环境访问不同的servlet上下文。

Enterprise.ear
  WAR1 /somewhere
  WAR2 /somewhereElse
  WAR3 /shared

Assuming a JSP in WAR1 bound to /somewhere: 假设WAR1中的JSP绑定到/ somewhere:

Reference the shared context with the optional 'context' attribute of the c:import tag (Standard JSTL tag). 使用c:import标记(标准JSTL标记)的可选“ context”属性引用共享上下文。 By default c:import uses the context it is in, which in war1 is /somewhwere. 默认情况下,c:import使用其所在的上下文,在war1中为/ somewhre。

<c:import url="/header.jsp"  context="/shared"/>

There are probably other ways... Perhaps just ignore your ear and just go with a full http request: 可能还有其他方法...也许只是忽略您的耳朵,然后执行完整的http请求:

<c:import url="http://www.somewhere.com/header.jsp"/>

I'm not certain on the syntax of the context attribute on the c:import tag. 我不确定c:import标记上context属性的语法。 But I believe that is the correct syntax (with the slash verse without, it might not matter). 但是我相信这是正确的语法(没有斜杠的话可能没关系)。

Use sitemesh. 使用sitemesh。 There is no need to change anything in the existing application. 无需更改现有应用程序中的任何内容。 Create a fresh war with sitemesh. 用sitemesh发起一场新的战争。 It can decorate content from multiple urls dynamically. 它可以动态修饰来自多个URL的内容。

http://raibledesigns.com/rd/entry/use_sitemesh_to_decorate_multiple http://raibledesigns.com/rd/entry/use_sitemesh_to_decorate_multiple

--Kiran.kumar --Kiran.kumar

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

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