-----BEGIN PGP SIGNED MESSAGE----- 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: > 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). First you can setup aliases in the Host, something like <Host name="mysite.com" appBase="fruit-webapps"> <Alias>apples.mysite.com</Alias> <Alias>bananas.mysite.com</Alias> <Alias>coconuts.mysite.com</Alias> </Host> 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. Cheers, Marcus -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkpDn84ACgkQXjXn6TzcAQkIHQCfXlSnQs/U8lsubWU+2TqYbLIR WEwAoJkiWqfJ0gPRz3ltUj3OwldGN79N =tIbH -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org