tags:

views:

883

answers:

2

Is it possible to have one appBase served up by multiple context paths in Tomcat?

I have an application base that recently replaced a second application base. My problem is a number of users still access the old context. I would like to serve the, now common, application from a single appBase yet accessed via either context. I took a swing at the low lying fruit and used a symbolic link in the 'webapps' directory... pointing the old context path at the new context path; it works, but feels "cheezy." And I don't like that a database connection pool is created for both contexts ( I would like to minimize the resources for connecting to the database ).

Anyway, if anyone knows of the "proper" way to do this I will greatly appreciate it. I'm using Tomcat 6.0.16 - no apache front end ( I suppose URL rewrite would be nice ).

+1  A: 

Yes, go into the Tomcat Web Application Manager and scroll down to "Deploy directory or WAR file located on server". For "Context Path (optional):" put in the new context. For "WAR or Directory URL:" put in the same path as your existing app.

Paul Croarkin
+2  A: 

I'm not sure if the answer above will prevent your webapp from loading twice (as you'd have to deploy it to both new and old context paths), but I could be mistaken. Another option would be to have an extremely simple webapp left in the old context, that does nothing except have one custom servlet filter declared in the web.xml that re-writes all requests to the new path (essentially simulating apache's rewrite rule behaviour). You'd have to write the filter class yourself but it would be quite trivial.

Pete
or make the extremely simple app just redirect to the actual application. This way you hit the second app only once and briefly and don't have to reinvent apaches rewrite behaviour
Olaf
That is what I meant by having only the intercepting filter in the simple app; do nothing but redirect to the actual application. I didn't imply that you should attempt to reproduce more advanced rewrite functionlity ;)
Pete