----- Original Message -----
From: "nlif" <[EMAIL PROTECTED]>
To: <users@tomcat.apache.org>
Sent: Thursday, October 23, 2008 4:56 PM
Subject: How to serve two docBases under the same context path
Hi all,
I am using Tomcat 6, and I have the following problem:
I am trying to separate the static content from the dynamic content of my
application. In production, I intend to use Apache to serve the static
content, and Tomcat to process requests to the application (mainly JSP's).
This can be accomplished by writing a deployment script that will copy
everything to its repsective place.
My problem, however, is with the development environment:
The static-content (css,js,images,html) is in one SVN project, and the
dynamic (JSP,WEB-INF,classes) is in another. Thus, on my local workspace,
they are on separate paths (e.g. c:\workspace\static and
c:\workspace\webapp). Now, I need some way to have Tomcat serve them as a
single context.
I thought I'd create two <context> elements in my server.xml file, but
they
will need to have the same PATH, like this:
<Context docBase="workspace\static" path="/myapp"/>
<Context docBase="workspace\webapp" path="/myapp"/>
Unfortunately, it is illegal to have two CONTEXT elements with the same
PATH
value.
nlif, if your framework allows for this, this is what we do...
Think of URLs like this
<a href="<%=request.getContextPath()%>/pathTo/myThing.html">View My
Thing</a>
and then it becomes fairly easy to do something like
<a href="<%=aBean.adjustURL(request,"pathTo/myThing.html")%>">View My
Thing</a>
I normally use a parameter init in a servlet to set the base contexts I
want.
Its not unlike the filter idea mentioned which is what I think you may have
to do if you cant do the above.
The thing is that now we just design the web app and let TC serve the static
stuff in *one* webapp.
But changing a param in web.xml lets us move the static resources to
anywhere, later.
So adjustURL is basically saying....
If external context is null then use request.getContextPath
else if html do this thing etc.
else if jpg do that thing etc.
I use a bean via an attribute which is easy to do outside of frameworks, you
may find a static (thread safe) adjustURL is easier, and decide to wrap the
idea up in EL or a special tag handler.
I dont use tags and EL but it may be a cool thing to try...
with a static class it would prbably look like
<a href="<%=packag.name.adjustURL(request,"pathTo/myThing.html")%>">View My
Thing</a>
with EL something like
<a href="${my:adjustURL(request,"pathTo/myThing.html")}">View My Thing</a>
with tags (big guess here) something like
<MY:a href ="/pathTo/myThing.html">View My Thing</MY:a>
which could be a very cool thing if I knew how to do it ;)
Hope that idea helps... TC has got all this cool powerful stuff, maybe worth
giving it a try ;)
---------------------------------------------------------------------------
HARBOR : http://www.kewlstuff.co.za/index.htm
The most powerful application server on earth.
The only real POJO Application Server.
See it in Action : http://www.kewlstuff.co.za/cd_tut_swf/whatisejb1.htm
---------------------------------------------------------------------------
If you cant pay in gold... get lost...
http://coolharbor.100free.com/debt/usadebt.htm
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]