Question

I want my application to run under URLs like:

www.myDomainName.com/welcome

instead of :

www.myDomainName.com/myAppName/welcome

How should I configure for this ?

I did found a way to accomplish this by specifying in context.xml(within the project directory) the path attribute as path="/". But not sure this is the best way to do it ?!

Another concern is that how would I then access the Tomcat server's root page, which I could previously access at localhost:8080?


Working on a JSF(Myfaces 2.2 beta) project running on Tomcat 7

Was it helpful?

Solution

How should I configure for this ?

Depends on the server used. This is not controllable from inside the WAR. Just consult the server-specific documentation how to configure the context path.

Note that this thus means that you should never hardcode the context path in your webapp's code and in Java source code always rely on getContextPath() method of HttpServletRequest and/or ServletContext and in Facelets source code on <h:outputStylesheet>, <h:outputScript>, <h:graphicImage>, <h:link>, <h:button>, etc components which automatically prepend the context path, or #{request.contextPath} to print it in plain <a>, <link>, etc elements.


I did found a way to accomplish this by specifying in context.xml(within the project directory) the path attribute as path="/". But not sure this is the best way to do it ?!

That's indeed the right way specifically for Tomcat.

An alternative would be to rename the WAR file to ROOT.war (and delete/rename the old apache-tomcat/webapps/ROOT folder representing the Tomcat default homepage). But this is generally somewhat clumsy. Generally you'd like to have a more specific filename of the WAR, often including the build version and leave the job to the context.xml.

Another alternative is to front the Tomcat instance by a HTTPD instance. This is also what most production servers do. This has among others the additional advantage that you can configure HTTPD to show a special "Sorry, this website is in maintenance, come back later!" page as HTTP 503 error page which would show up when you shutdown/restart/redeploy Tomcat.


Another concern is that how would I then access the Tomcat server's root page, which I could previously access at localhost:8080?

Simply rename apache-tomcat/webapps/ROOT folder to the desired name which should represent the new context path. E.g. apache-tomcat/webapps/tomcathome which should then make it available on http://localhost:8080/tomcathome.

OTHER TIPS

I usally set up an apache2 webserver and a tomcat Server. Then I do all the vhost setup apache side and route the traffic for a specific domain or path to the destination path of the Tomcat server via mod_proxy. This way you can access your host.tld:8080 and set up your domain AS you wish.

So basically a call to www.host.tld/welcome would cause the Apache to route the request internally to host.tld: 8080/myApp/welcome.

HTH and sorry for the brief explanation i have to use my mobile phone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top