You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by xianwinwin <xi...@gmail.com> on 2008/01/24 22:05:40 UTC
is it possible to pass a parameter to an interceptor from the xml
file?
Hi all,
I wonder if it is possible to pass a parameter with a value to an
interceptor.
Example:
I have the following interceptor:
<interceptor name="authentication"
class="com.struts.security.AuthenticationInterceptor"/>
(parameterGivenInXmlFile==4)
the implementation is:
public String intercept (ActionInvocation invocation) throws Exception
{
...
if (parameterGivenInXmlFile ==3)
//do something
....
}
thanks for any input
--
View this message in context: http://www.nabble.com/is-it-possible-to-pass-a-parameter--to-an-interceptor-from-the-xml-file--tp15074977p15074977.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: is possible to pass a parameter to an interceptor from the xml file?
Posted by Chris Pratt <th...@gmail.com>.
On Jan 24, 2008 1:04 PM, xianwinwin <xi...@gmail.com> wrote:
>
> Hi all,
>
> I wonder if it is possible to pass a parameter with a value to an
> interceptor.
>
> Example:
>
> I have the following interceptor:
>
> <interceptor name="authentication"
> class="com.struts.security.AuthenticationInterceptor"/>
>
> (parameterGivenInXmlFile==4)
>
>
> the implementation is:
>
> public String intercept (ActionInvocation invocation) throws Exception
> {
> ...
> if (parameterGivenInXmlFile ==3)
> //do something
> ....
> }
>
>
> thanks for any input
>
If you need the parameters on a per action basis, you can use:
<param name="parameterGivenInXmlFile">3</param>
inside the <action> tag in your struts.xml file. Then in your
interceptor you can access the parameter using:
invocation.getProxy().getConfig().getParams().get("parameterGivenInXmlFile");
I'm not sure if you can use the <param> tag inside the <interceptor>,
but that might be possible as well.
(*Chris*)
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: is it possible to pass a parameter to an interceptor from the
xml file?
Posted by ravi_eze <ra...@ivycomptech.com>.
hi,
i think whats not possible is
...
< param name="...">${actionclass'sVariable} </..>
...
i.e. getting the variable form action calss and accessing it or evaluating
an expression as the param value.
any ideas how this is possible
cheers,
ravi
nuwan chandrasoma-2 wrote:
>
> Hi,
>
> yes it is possible., just implement a setter and getter method for the
> parameter you have in the struts.xml file. and it will be available to
> you in the intercept method.
>
> eg:-
>
> // in the intercept class..
>
> private String httpPort;
>
> public String getHttpPort() {
> return httpPort;
> }
>
> public void setHttpPort(String httpPort) {
> this.httpPort = httpPort;
> }
>
> // in the struts.xml
>
> <interceptor-stack name="SecureStack">
> <interceptor-ref name="secure">
> 80
> </interceptor-ref>
>
> the value 80 will be inject to the variable httpPort in the interceptor
> class.,
>
> Thanks,
> Nuwan.
> (http://struts2-ssl-plugin.googlecode.com/)
>
>
>
>
>
> xianwinwin wrote:
>> Hi all,
>>
>> I wonder if it is possible to pass a parameter with a value to an
>> interceptor.
>>
>> Example:
>>
>> I have the following interceptor:
>>
>> <interceptor name="authentication"
>> class="com.struts.security.AuthenticationInterceptor"/>
>>
>> (parameterGivenInXmlFile==4)
>>
>>
>> the implementation is:
>>
>> public String intercept (ActionInvocation invocation) throws Exception
>> {
>> ...
>> if (parameterGivenInXmlFile ==3)
>> //do something
>> ....
>> }
>>
>>
>> thanks for any input
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/is-it-possible-to-pass-a-parameter--to-an-interceptor-from-the-xml-file--tp15074977p15080834.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: is it possible to pass a parameter to an interceptor from the
xml file?
Posted by xianwinwin <xi...@gmail.com>.
THANK YOU nuwan !!! this is exactly what i was looking for
--
View this message in context: http://www.nabble.com/is-it-possible-to-pass-a-parameter--to-an-interceptor-from-the-xml-file--tp15074977p15090339.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: is it possible to pass a parameter to an interceptor from the
xml file?
Posted by Nuwan Chandrasoma <my...@gmail.com>.
Hi,
yes it is possible., just implement a setter and getter method for the
parameter you have in the struts.xml file. and it will be available to
you in the intercept method.
eg:-
// in the intercept class..
private String httpPort;
public String getHttpPort() {
return httpPort;
}
public void setHttpPort(String httpPort) {
this.httpPort = httpPort;
}
// in the struts.xml
<interceptor-stack name="SecureStack">
<interceptor-ref name="secure">
<param name="httpPort">80</param>
</interceptor-ref>
the value 80 will be inject to the variable httpPort in the interceptor
class.,
Thanks,
Nuwan.
(http://struts2-ssl-plugin.googlecode.com/)
xianwinwin wrote:
> Hi all,
>
> I wonder if it is possible to pass a parameter with a value to an
> interceptor.
>
> Example:
>
> I have the following interceptor:
>
> <interceptor name="authentication"
> class="com.struts.security.AuthenticationInterceptor"/>
>
> (parameterGivenInXmlFile==4)
>
>
> the implementation is:
>
> public String intercept (ActionInvocation invocation) throws Exception
> {
> ...
> if (parameterGivenInXmlFile ==3)
> //do something
> ....
> }
>
>
> thanks for any input
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org