Read and respond to this message at: https://sourceforge.net/forum/message.php?msg_id=3236127 By: ckoenigsberg
Dynamically determing the context root, for URL construction, can be tricky, we have found, inside a web application. e.g. for "http://myserver/myapp/foo" you want to dynamically make server root relative URL's like "/myapp/foo1", where the "myapp" is dynamically determined. There are the Struts tools to do it, which have migrated, between Struts version 1.1 and more recent versions (apparently due to fuller integration of "modules"). But to use these, you need to pass in a Struts ActionMapping. Then there is ServletContext.getServletContextName(), which you can get to as long as you have an HttpSession or Request. But this "servlet context name" is not necessarily the same as the "context root", in the URL's for the deployed web application on the server! We have found, at least in Websphere Application Server (developing and testing in Websphere Studio Application Developer/Rational Application Developer) that the "ServletContext.getServletContextName()" will return the value set in the web.xml for the "display-name" element. IF you are careful to always set the web.xml "display-name" the same as the context root, then (at least in Websphere), ServletContext.getServletContextName()" WILL return the value you want, and you can use that, to construct your server-relative URL. We've recently started adding a Struts PlugIn (implementing their PlugIn interface, specifying plugin in the struts-config.xml) which, when its "init" is called by the Struts ActionServlet, will get the ServletContext.getServletContextName, use it to determine the context root, and then save that in a static variable, providing a "getUrlRoot()" static method that we can use from that point on, anywhere in our web app. But like I said, we have had problems where someone changed the context root, but not the "display-name", or vice versa, and then our "getUrlRoot()" no longer returns the right string for the server root-relative URL root. We even use the getUrlRoot for jsp's to dynamically build CSS links, or javascript src links, etc. ______________________________________________________________________ You are receiving this email because you elected to monitor this forum. To stop monitoring this forum, login to SourceForge.net and visit: https://sourceforge.net/forum/unmonitor.php?forum_id=249318 ------------------------------------------------------- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click _______________________________________________ displaytag-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/displaytag-user

