You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ivan Vasquez <iv...@itos.uga.edu> on 2004/07/12 18:14:02 UTC
How to read from web.xml?
Hi,
How can I read from web.xml, say, the application's display name? I've
tried several things, but no luck. This isn't really Struts-specific,
but I'm sure this is an easy one for many of you.
Thanks,
Ivan.
Re: How to read from web.xml?
Posted by Jason Lea <ja...@kumachan.net.nz>.
Ivan Vasquez wrote:
>Hi,
>
>How can I read from web.xml, say, the application's display name? I've
>tried several things, but no luck. This isn't really Struts-specific,
>but I'm sure this is an easy one for many of you.
>
>Thanks,
>Ivan.
>
>
>
in an struts action you should be able to use:
getServlet().getServletContext().getServletContextName()
from javadocs:
javax.servlet.ServletContext.getServletContextName()
Returns the name of this web application correponding to this
ServletContext as specified in the deployment descriptor for this web
application by the display-name element.
(haven't tried this myself though)
--
Jason Lea
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to read from web.xml?
Posted by Craig McClanahan <cr...@apache.org>.
Ivan Vasquez wrote:
>Hi,
>
>How can I read from web.xml, say, the application's display name? I've
>tried several things, but no luck. This isn't really Struts-specific,
>but I'm sure this is an easy one for many of you.
>
>Thanks,
>Ivan.
>
>
>
The web.xml file is available as a resource that can be accessed via the
ServletContext for your webapp. For example, you can say something like:
ServletContext context = ...; // Get a reference to our servlet context
InputStream stream = context.getResourceAsStream("/WEB-INF/web.xml");
Now you've got an input stream to read the contents ... you'll probably
want to use an XML parser to parse the contents -- google for JAXP to
see the API that Java provides for this purpose. Or, you might consider
using the Commons Digester package (included with Struts), which is what
Struts itself uses to parse this very resource, in order to figure out
how the controller servlet is mapped. Looking at the source code for
ActionServlet should give you some useful clues.
Craig
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org