tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Jones" <martin.jo...@ed.ac.uk>
Subject Re: How to share static content across multiple tomcat webapps
Date Tue, 01 May 2007 09:06:54 GMT
Thanks for the reply.

After mulling this over, I've thought of another way to do it
(apologies if I'm not using the correct terminology here).  Have the
static content in a single directory on my development machine, then
use my Ant build script to have the contents included in the .war
file.  Then, when I make any changes to the static content, I just
have to rebuild and redeploy .war files for each webapp I'm running.
There would be multiple copies of sidebar.html and images, etc. on the
server, but that wouldn't matter as I would never edit them directly.

This seems like a good compromise - any thoughts?

Thanks,

Martin

On 4/30/07, Rashmi Rubdi <rashmi.sub@gmail.com> wrote:
> Hi Martin,
>
> On 4/30/07, Martin Jones <martin.jones@ed.ac.uk> wrote:
> > Hi,
> >
> > This seems like an obvious question but I'd appreciate any answers. I
> > have several webapps running under tomcat that need to be able to
> > include the same sidebar in their .jps.  if the sidebar is within the
> > context, this works fine:
> >
> > <%@ include file="sidebar.html" %>
> >
> > However this requires me to keep a copy of sidebar.html (and all the
> > images) in each .war.  I'd rather keep a single copy of sidebar.html.
> > If I make a new context "static" in tomcat and place the sidebar +
> > images there, I can access it fine in my browser with the url:
> >
> > http://localhost:8080/static/sidebar.html
> >
> > but the naive change to the jsp:
> >
> > <%@ include file="../static/sidebar.html" %>
>
> The include directive is out of the question because according to it's syntax
> http://java.sun.com/products/jsp/syntax/2.0/syntaxref209.html#1003408
> it only accepts URLs that are relative to the web application (a.k.a Context).
>
>
> > fails with "the path specifies a resource outside the web
> > application".  Using jstl and import:
> >
> > <c:import url="../static/sidebar.html"/>
>
> JSTL's c:import tag has an attribute called context,
> http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/c/import.html
> which allows one to access resources from other contexts (a.k.a web
> applications) , however in order to function properly the crossContext
> attribute of the web application's Context node must be enabled (set
> to true).
>
> From my experience setting crossContext to true has caused other
> conflicts when 2 resources (Java Classes) have the same name in 2
> different web applications that have crossContext enabled ---- it
> could be that there was something wrong in my configuration. But, I'm
> just letting you know about it.
>
> >
> > leads to:
> >
> > javax.servlet.jsp.JspTagException: /../static/sidebar.html
> >
> > However, if I use the absolute path:
> >
> > <c:import url="http://localhost:8080/static/sidebar.html"/>
> >
> > the page is fine, but because the paths to the images are copied
> > directly from sidebar.html and included in the .jsp they are
> > incorrect.
>
> In this case you would also need to change the URLs of the images to
> be the absolute URL.
>
> >
> > It seems to me that what I'm trying to accomplish is a fairly common
> > thing; I'd appreciate any pointers.
>
> Normally it is considered bad practice to hardcode the entire URL, you
> may want to store the domain etc in a constant and prefix it to the
> rest of the URL.
>
> Also, there might be better ways to accomplish this.
>
> I don't know much about JNDI but it comes to mind, is it possible to
> store images as a global JNDI resource.
>
> > Thanks,
> >
> > Martin
> >
>
> -Regards
> Rashmi
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
Martin Jones
Bioinformatics Team
Centres for Cardiovascular Science and Inflammation Research,
University of Edinburgh,
Queen's Medical Research Institute,
47 Little France Crescent
Edinburgh EH16 4TJ
United Kingdom
T: +44 131 242 6700

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message