You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christian Schröder <cs...@deriva.de> on 2007/04/23 21:07:39 UTC

How can I control the path of my web app?

Hi list!
It seems that I have not yet understood the concept of webapps, 
contexts, servlet mappings etc. I have a long experience with good old 
Apache web server, but I'm quite new to servlet development / deployment 
in general and Tomcat in particular.
My problem is as follows: I have a Tomcat 5.5 server with the 
out-of-the-box configuration. And I have a webapp which is packed in a 
war file, say "MyWebApp.war". This file contains some classes (servlets) 
in the "WEB-INF/classes" directory, a "web.xml" file in "WEB-INF" and a 
"context.xml" in "META-INF". I have write access to the "webapps" 
directory of the server (but only to this directory), so I can place the 
war file there. Tomcat (having "autoDeploy" enabled) then creates a 
directory "MyWebApp" in the "webapps" directory and extracts everything 
from the war file to this directory. After this has been done, I can 
find my servlets at the url "http://127.0.0.1:8080/MyWebApp/..."
Ok, this works fine. But now I want my servlets to be accessible at 
"http://127.0.0.1:8080/foo/bar/MyWebApp/...". How can I achieve this? I 
have tried to create the directory structure in the "webapps" directory 
and put the war file into "webapps/foo/bar", but then Tomcat doesn't 
unpack the war file at all. Simply changing the "path" attribute of the 
"Context" element in my "context.xml" file didn't work, too.
Is this possible at all if I only have access to the "webapps" directory 
(and not, for example, to the manager application)?

Thanks a lot for your help,
    Christian

My context.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/MyWebApp"/>

My web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <servlet>
        <servlet-name>TestServlet</servlet-name>
        <servlet-class>TestServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/TestServlet</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>TestServlet</welcome-file>
    </welcome-file-list>
</web-app>

-- 
Deriva GmbH                         Tel.: +49 551 489500-42
Financial IT and Consulting         Fax:  +49 551 489500-91
Hans-Böckler-Straße 2                  http://www.deriva.de
D-37079 Göttingen

Deriva CA Certificate: http://www.deriva.de/deriva-ca.cer


---------------------------------------------------------------------
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 can I control the path of my web app?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net] 
> Subject: Re: How can I control the path of my web app?
> 
> Does the manager application allow you to deploy WARs with custom
> configuration (such as this), or does it only allow vanilla 
> WARs with a context.xml within them?

It wouldn't surprise me if it does, but I haven't been able to figure it
out yet.  You can specify a path and an alternate location for the .xml
file; there may be some trick to getting it work with a multi-level
path, but it's not obvious.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
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 can I control the path of my web app?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuck,

Caldarale, Charles R wrote:
>> From: Christian Schröder [mailto:cs@deriva.de] 
>> Subject: Re: How can I control the path of my web app?
>>
>> Do I have any chance if I don't have access to any directory 
>> outside of the webapps directory?
> 
> Not that I can figure out, but others might have some ideas.

Does the manager application allow you to deploy WARs with custom
configuration (such as this), or does it only allow vanilla WARs with a
context.xml within them?

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGLTLX9CaO5/Lv0PARAkYOAJwJ8irCITrkpmrcs+a2DvsxGaQMRwCeNHpM
WTfMm/mAWo8X+TrgHDpC5qU=
=jPs5
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
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 can I control the path of my web app?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christian Schröder [mailto:cs@deriva.de] 
> Subject: Re: How can I control the path of my web app?
> 
> Do I have any chance if I don't have access to any directory 
> outside of the webapps directory?

Not that I can figure out, but others might have some ideas.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

---------------------------------------------------------------------
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 can I control the path of my web app?

Posted by Christian Schröder <cs...@deriva.de>.
Caldarale, Charles R wrote:

> If you want to use a multi-level URL path to access your webapp, you need to do two things:
>
> 1) Place your .war file outside of Tomcat's directory structure to avoid having it deployed twice.
>
> 2) Create a file named foo#bar#MyWebApp.xml in conf/Catalina/[host] that contains a <Context> element with a docBase attribute pointing to the absolute location of your .war file.  (The value of [host] in the above is usually localhost, unless you've fiddled with the <Host> element in the server.xml file.)  This will override the META-INF/context.xml file that you may have in your webapp.
>   

Do I have any chance if I don't have access to any directory outside of
the webapps directory?

Regards,
    Christian

-- 
Deriva GmbH                         Tel.: +49 551 489500-42
Financial IT and Consulting         Fax:  +49 551 489500-91
Hans-Böckler-Straße 2                  http://www.deriva.de
D-37079 Göttingen

Deriva CA Certificate: http://www.deriva.de/deriva-ca.cer


---------------------------------------------------------------------
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 can I control the path of my web app?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christian Schröder [mailto:cs@deriva.de] 
> Subject: How can I control the path of my web app?
> 
> But now I want my servlets to be accessible at 
> "http://127.0.0.1:8080/foo/bar/MyWebApp/...".

If you want to use a multi-level URL path to access your webapp, you need to do two things:

1) Place your .war file outside of Tomcat's directory structure to avoid having it deployed twice.

2) Create a file named foo#bar#MyWebApp.xml in conf/Catalina/[host] that contains a <Context> element with a docBase attribute pointing to the absolute location of your .war file.  (The value of [host] in the above is usually localhost, unless you've fiddled with the <Host> element in the server.xml file.)  This will override the META-INF/context.xml file that you may have in your webapp.

Also, remove the path attribute from your context.xml; this is not allowed unless the <Context> element is within server.xml, which is strongly discouraged.  The path is determined by the name of the .war file (or directory) if under webapps, or the name of the .xml files under conf/Catalina/[host].

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

---------------------------------------------------------------------
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 can I control the path of my web app?

Posted by Rashmi Rubdi <ra...@gmail.com>.
Hi Christian,

MyWebApp is a Context (web application ) in Web Container (Tomcat) terminology.

It appears to me that you would like MyWebApp to function as a path or
a directory.

One approach I would try myself is: instead of deploying the app at
some context such as MyWebApp, I would deploy it at the ROOT context
-- this way my application would be accessible at
http://localhost:8080/   instead of at http://localhost:8080/MyWebApp/

Once the application is configured to be accessible at
http://localhost:8080/ , it gives a lot of flexibility with path or
directory structure under the app.

Perhaps the reason why you are accessing your apps at
http://localhost:8080/MyWebApp/ is because you may have multiple
applications. In this case each app could also be accessed on it's own
ROOT context by configuring virtual hosts as in
http://first_host:8080/
http://second_host:8080/   etc.

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