struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ashutosh Satyam" <ashutosh.sat...@alopa.com>
Subject RE: How to read a parameter in web.xml from Action class
Date Thu, 20 May 2004 05:15:02 GMT
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("myParamValue");


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


Mime
View raw message