tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcus Better <>
Subject Re: The best place for implementing context specific behavior?
Date Thu, 25 Jun 2009 16:03:26 GMT
Hash: SHA1

Jonathan Mast wrote:
> I have a webapp that I would like to behave in a context (actually
> host)-specific manner.  Where is the best place to initialize the
> context/host specific functionality?

I implemented something very similar a few days ago.

> Let me demonstrate what I'm talking about.  Lets say I have a webapp Fruit
> located in folder webapps/fruit.
> I want to define:
> etc  ...
> all of which point to webapps/fruit  (these are hosts with a "/" context
> pointing to "webapps/fruit" as the docBase, to be more precise).

First you can setup aliases in the Host, something like

<Host name="" appBase="fruit-webapps">

Then install your webapp into "fruit-webapps/ROOT.war".

> Where in the fruit app is the best place for instance of Fruit to
> introspect itself (basically look for what host name it is defined under)
> and prepare accordingly?

In this setup there is only one webapp, so it cannot be done per webapp 
context, or even per servlet instance.

> Of course I could always call request.getLocalName(), but that would be
> inefficient as it would have to be invoked on every request.

I check request.getServerName() in the main index.gsp (it's a Grails app) 
and then put the result into the session. If you don't use sessions and have 
more than one servlet, I guess you can do the check in a filter. I don't 
think it's that inefficient.



Version: GnuPG v1.4.9 (GNU/Linux)


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message