Tomcat – How to define context path of application in Tomcat 6

tomcattomcat6

Application is deployed on Tomcat6 on context path "/environame/appname".

<Context
...
        path="/environame/appname"
...
</Context>

But I cannot access my application using following URL:

http://localhost:8080/environame/appname

I have to use underscore instead of slash between "environame" and "appname".

http://localhost:8080/environame_appname

Tomcat 5 works differently.
In case of Tomcat 5 there will not be underscore in the URL:

http://localhost:8080/environame/appname

What should I change in configuration of my application or Tomcat 6 to access my application using slash instead of underscore between "environame" and "appname"?

UPDATE:

path The context path of this web application, which is matched against the beginning of each request URI to select the appropriate
web application for processing. All of the context paths within a
particular Host must be unique. If you specify a context path of an
empty string (""), you are defining the default web application for
this Host, which will process all requests not assigned to other
Contexts.

The value of this field must not be set except when statically
defining a Context in server.xml, as it will be inferred from the
filenames used for either the .xml context file or the docBase.

http://tomcat.apache.org/tomcat-5.5-doc/config/context.html

We store context xml file to $CATALINA_HOME/conf/Catalina/localhost/environame_appname.xml file.
Tomcat 5.0.28 uses path attribute of Context element.
Tomcat 6 uses name of context xml file.
Is it possible to change configuration to use path attribute instead of the name of the xontext xml file?

ANSWER:
There is a bug bug#46713

If a path attribute is set inside the context tag in context xml's it
is ignored. Instead the path is set to "/" + . While it nice that even pathes with '/' can
be encoded in the file name by replacing '/' with '#' it is very
confusing that an existing path attribute is simply ignored.

So, I need just rename my context xml file to environame#appname.xml.

Best Answer

A long time ago (tomcat 4 I think) it was possible to deploy a war archive with the name environame_appname.war and tomcat made it available via the url environame/appname/... I'm not sure if this still works (and have no time yet to test it). Tomcat does some replacement with slashes and underscores.

Another way to achieve your goal would be using apache and mod_proxy, mod_proxy_ajp (or mod_proxy_html) and mod_rewrite. Then you can define two applications in tomcat (app01 and app02), define a proxy rule that forwards request to /app01 (resp /app02) to your tomcat and a rewrite rule that rewrites requests to /env01/app to /app01 and /env02/app02 to /app02.

Related Topic