struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joe Hertz" <jhe...@speakeasy.net>
Subject RE: How to read a parameter in web.xml from Action class
Date Thu, 20 May 2004 10:31:52 GMT
Why should he?

He's already got a servlet context. He's got to have a web.xml *anyway*,
so why not use it? 

Yeah, there are a list of things that could dictate using JNDI, but this
isn't necessarily one of them). I mean unless you like having loooong
classpaths.... :-)

> -----Original Message-----
> From: Iván Rodríguez [mailto:ivan@interd4u.com] 
> Sent: Thursday, May 20, 2004 6:02 AM
> To: Struts Users Mailing List
> Subject: Re: How to read a parameter in web.xml from Action class
> 
> 
> Why don t you use JNDI ?
> 
> ----- Original Message ----- 
> From: "Frank Burns" <frankburns@the-hub.demon.co.uk>
> To: "Struts Users Mailing List" <user@struts.apache.org>
> Sent: Thursday, May 20, 2004 11:47 AM
> Subject: Re: How to read a parameter in web.xml from Action class
> 
> 
> > Excellent. Thank you Ashutosh.
> >
> > ----- Original Message -----
> > From: "Ashutosh Satyam" <ashutosh.satyam@alopa.com>
> > To: "Struts Users Mailing List" <user@struts.apache.org>
> > Sent: Thursday, May 20, 2004 6:40 AM
> > Subject: RE: How to read a parameter in web.xml from Action class
> >
> >
> > One more addendum to this.
> >  In case you want this intialization parameter to be 
> available to all 
> > the servlets in your web application, then it should be 
> defined like 
> > this in web.xml
> >
> > <context-param>
> >  <param-name>myParamName</param-name>
> >  <param-value>myParamValue</param-value>
> > </context-param>
> >
> > Now you can call getInitParameter("myParamName") on the 
> ServletContext 
> > to retrieve it's value.
> >
> > ServletContext ctxt = servlet.getServletContext();
> > String  sname = ctxt.getInitParameter("myParamName");
> >
> >      OR
> >
> > String paramValue =
> >
> request.getSession().getServletContext().getInitParameter("myP
> aramValue");
> >
> > There is one ServletContext per "web application" per Java Virtual
> Machine.
> >
> > If intialization parmaeter is defined for a specific servlet, then 
> > it'll
> be
> > accessible only by this servlet. To retrieve this parameter need to 
> > call
> > getInitParameter() on this servlet.
> >
> > Hope it clears your doubt.
> > - Ashutosh
> >
> > -----Original Message-----
> > From: Ashutosh Satyam
> > Sent: Thursday, May 20, 2004 10:45 AM
> > To: Struts Users Mailing List
> > Subject: RE: How to read a parameter in web.xml from Action class
> >
> >
> > Try using the below mentioned code to read intialization parameter 
> > defined in the Web descriptor file.
> >
> > String sname = servlet.getInitParameter("myParamName");
> >
> >            OR
> >
> > ServletConfig config = servlet.getServletConfig();
> > String sname = config.getInitParameter("myParamName");
> >
> > 'servlet' is a field defined in Action class, so it can be used in 
> > your action class. It returns the controller servlet instance (i.e 
> > instance of the ActionServlet ) to which
> > the Action clas is attached to.
> >
> > Regards,
> > Ashutosh
> >
> > -----Original Message-----
> > From: Frank Burns [mailto:frankburns@the-hub.demon.co.uk]
> > Sent: Thursday, May 20, 2004 8:59 AM
> > To: Struts Users Mailing List
> > Subject: Re: How to read a parameter in web.xml from Action class
> >
> >
> > Sorry, see my CORRECTION below:
> >
> > ----- Original Message -----
> > From: "Frank Burns" <frankburns@the-hub.demon.co.uk>
> > To: "Struts Users Mailing List" <user@struts.apache.org>
> > Sent: Thursday, May 20, 2004 4:19 AM
> > Subject: How to read a parameter in web.xml from Action class
> >
> >
> > > Hi,
> > >
> > > From an Action class, I want to read a parameter specified in the
> web.xml
> > > file. I thought I could place it in an <init-param> block, within 
> > > the <servlet-name>action</servlet-name> element, like this:
> > >
> > >     <init-param>
> > >       <param-name>myParamName</param-name>
> > >       <param-value>myParamValue</param-value>
> > >     </init-param>
> > >
> > > and then read it within the Action class using:
> > >
> > >     String paramValue =
> > >
> request.getSession().getServletContext().getInitParameter("myP
> aramValue");
> >
> >
> > CORRECTION: 
> > 
> request.getSession().getServletContext().getInitParameter("myParamName
> > ");
> >
> > >
> > > But I get null.
> > >
> > > What am I doing wrong?
> > >
> > > Thanks,
> > >
> > > Frank.
> > >
> > >
> > > 
> --------------------------------------------------------------------
> > > -
> > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail: user-help@struts.apache.org
> > >
> >
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message