tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Mast <jhmast.develo...@gmail.com>
Subject The best place for implementing context specific behavior?
Date Wed, 24 Jun 2009 18:08:02 GMT
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?

Let me demonstrate what I'm talking about.  Lets say I have a webapp Fruit
located in folder webapps/fruit.
I want to define:
apples.mysite.com
bananas.mysite.com
coconuts.mysite.com
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).

When someone visits apples.mysite.com they see an apple, when they visit
bananas.mysite.com they see a banana, and so on.

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?

I've looked into using Context Parameters in the server.xml declarations but
I would like to avoid this if possible b/c this functionally is more
elegantly determined through introspection (the web-app saying "what host do
i belong to?").

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

I guess what I'm looking for someplace in the context initialization process
where i could hook into and do my stuff and have it apply to the entire
context throughout it's lifecycle.  Can't seem to find it digging around the
javax.servlet.* javadocs.

thanks

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message