tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lisa Simaki <>
Subject Virtual Hosts Kill My JSPs
Date Fri, 02 Apr 2004 17:18:54 GMT

Thought I'd try again.... :)

We are using Tomcat v5.0.19 as a stand-alone server,
with the Coyote HTTP 1.1 Connector, on Windows 2000.
We have Tomcat configured with two virtual hosts
(i.e., two <Host> elements). The virtual hosting is
working great except for a problem with identically
named JSPs across hosts:

In a nutshell, when Tomcat translates a JSP into a
servlet, it is *NOT* taking into account which <Host>
the JSP belongs to. It translates the JSP into a
servlet and dumps the resulting Java source code in
the same directory, regardless of what <Host> the JSP
came from. 

This causes a big problem if the different hosts have
a JSP that happens to be the same name, like, say,
index.jsp. Since the generated Java code
( is dumped into the same directory,
regardless of which <Host> the JSP originated from,
Tomcat will serve the index.jsp that got translated
first. So, both hosts end up sharing the same

In my server.xml I have two <Host> elements

<Host name="" debug="0"
      unpackWARs="true" deployOnStartup='true'
   <Context path="/" docBase="" debug="0"
            reloadable="false" />

<Host name="" debug="0"
      unpackWARs="true" deployOnStartup='true'
  <Context path="/" docBase="" debug="0"
           reloadable="false" />

The "name" attribute of the first Host element is
"" and the "name" attribute on
the second Host is "". Of course, I also
have the Windows "hosts" file set up so that both host
names are associated with In other words,
the "hosts" file has entries for both
and and they both point to

Both test1 and test2 have their own directories. In
other words, both "appBase" attributes of the <Host>
elements point to the directory appropriate to that
host ( or 

I hope this is clear so far. 

With Tomcat running I can browse to either or and the
correct page is served. Tomcat seems to be using
virtual hosting just fine....except...

If both test1 and test2 have a JSP with the same name
(like, say, index.jsp), then there's confusion. The
first index.jsp that gets compiled is the one that
gets served for *BOTH* hosts. For example:

Assume no JSPs are yet compiled.
I go to, causing the
test1's index.jsp to be compiled and rendered. That's
expected. Now, go to 
-- the result is still test1's version of index.jsp!

Now, if I modify test2's index.jsp and I go to I see what I expect --
test2's JSP with the modification I just made. But now
if I go to I also see
test2's index.jsp, not test1's JSP!!!

Now, I know, partially why this is happening. You know
that Tomcat uses a separate directory to store
compiled JSPs. As I mentioned, Tomcat is not
differentiating between hosts when it writes the Java
source code (from the translated JSP) to this
directory. It's simply putting *all*
compiled JSPs into the same directory (WINNT/temp).
Since both test1 and test2 have identically named
"index.jsp" files, Tomcat does not distinguish them.
In both cases it generates "" as needed,
overwriting the previous version. That is the crux of
what's causing my grief.

One would think Tomcat would build a directory
structure reflective of the host name and contexts so
that identically named JSPs from different hosts do
not over-write each other.

Can anyone offer any comments on this? Is anyone still
reading at this point?



Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message