The problem is:
I have a web app and this web app is deployed to the $TOMCAT_HOME/webapps/XXX
directory.
I can reach that on the http://localhost:8080/XXX
address
BUT, I would like to reach the web app on the http://localhost:8080/YYY
address too.
I added the following to the server.xml:
<Server>
<Service>
<Engine>
<Host>
.......
<Context path="/YYY" docBase="XXX"></Context>
</Host>
</Engine>
</Service>
</Server>
It helped but the Tomcat started two web contexts and it caused some other problem. Is it possible to create a "multiple" address for one web app?
To change the context root of a web application that is already available in the Eclipse workspace, simply right-click on the web project and call the “Properties” action from the context menu.
The docBase attribute is a path to the WAR file or exploded deployment directory. It is relative to the webapps directory, although an absolute path can be used. The path attribute is the one we are most interested in, as it defines the context path of the application.
The context path refers to the location relative to the server's address which represents the name of the web application. By default, Tomcat derives it from the name of the deployed war-file. So if we deploy a file ExampleApp. war, it will be available at http://localhost:8080/ExampleApp.
The url of web application is assebled as follows:
PROTOCOL://DOMAIN:PORT/CONTEXT/pagename
The solutions for having same app on two distinct address are as follows:
If you want to differ only in protocol (let's say between http, and https) then just have 2 connectors in server.xml.
if you want to differ in DOMAIN name, then this is solved on DNS level.
If you want to differ in context name (web application name), you should put apache in front (mod_proxy or mod_ajp) and then create a rewrite rule (mod_rewrite). let's say rewrite all from /a/*
and /b/*
to /c/*
If you want to differ in page name, you should use servlet mappings.
Putting apache in front of tomcat via mod_proxy is very easy, there are multiple resources on the web. Very bad would be to duplicate applications (have everything loaded twice).
As for your question, i would advise agains duplication in server.xml.
<Context docBase="myapp" path="/address1" reloadable="true" />
<Context docBase="myapp" path="/address2" reloadable="true" />
This is killer for memory, as well as for session mechanisms, concurency, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With