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 usi开发者_C百科ng .jar files?
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.
Tag files can be packaged in a jar.
They are JSP files with a ".tag" extension. They can be parameterized.
I have never tried but logically speaking you can very well do it by putting all your JSP's into a common folder
I think of it as accessing a different servlet context from the one you are in. Something like
Enterprise.ear
WAR1 /somewhere
WAR2 /somewhereElse
WAR3 /shared
Assuming a JSP in WAR1 bound to /somewhere:
Reference the shared context with the optional 'context' attribute of the c:import tag (Standard JSTL tag). By default c:import uses the context it is in, which in war1 is /somewhwere.
<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:
<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. But I believe that is the correct syntax (with the slash verse without, it might not matter).
Use sitemesh. There is no need to change anything in the existing application. Create a fresh war with sitemesh. It can decorate content from multiple urls dynamically.
http://raibledesigns.com/rd/entry/use_sitemesh_to_decorate_multiple
--Kiran.kumar
精彩评论