You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Martin Jones <ma...@ed.ac.uk> on 2007/04/30 15:53:29 UTC
How to share static content across multiple tomcat webapps
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" %>
fails with "the path specifies a resource outside the web
application". Using jstl and import:
<c:import url="../static/sidebar.html"/>
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.
It seems to me that what I'm trying to accomplish is a fairly common
thing; I'd appreciate any pointers.
Thanks,
Martin
--
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
Re: How to share static content across multiple tomcat webapps
Posted by Rashmi Rubdi <ra...@gmail.com>.
Hi Martin,
On 5/1/07, Martin Jones <ma...@ed.ac.uk> wrote:
> 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?
It depends, if you have 10 different websites, then it would create 10
different copies. It may or may not become a maintenance nightmare in
the future.
I think this thread
http://www.theserverside.com/news/thread.tss?thread_id=27172 has a few
good suggestions.
1) one poster (post #6 from the top) suggested creating a separate
webapplication (Context) to hold only the common static resources
(html, images etc) and set crossContext="true" only for that static
application.
2) some have suggested creating a Filter for this, I don't know about
Filters yet but it seems like a possible solution.
>
> 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
Re: How to share static content across multiple tomcat webapps
Posted by Martin Jones <ma...@ed.ac.uk>.
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 <ra...@gmail.com> wrote:
> Hi Martin,
>
> On 4/30/07, Martin Jones <ma...@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
Re: How to share static content across multiple tomcat webapps
Posted by Rashmi Rubdi <ra...@gmail.com>.
Hi Martin,
On 4/30/07, Martin Jones <ma...@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