wood burning stoves 2.0*
The moose likes Struts and the fly likes struts 2 passing parameter to interceptor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts 2 passing parameter to interceptor" Watch "struts 2 passing parameter to interceptor" New topic
Author

struts 2 passing parameter to interceptor

shashi wagh
Ranch Hand

Joined: Oct 30, 2008
Posts: 38
In my struts 2 application I have a LoginInterceptor
I want to pass some parameter through the struts.xml file
How can I pass the parameter to the interceptor.
In other words I want the parameter which I send to the action from struts.xml

e.g.


I want menuId in interception which I have configure for this action.

How do I get the value In interceptor.

I have already try for getter setter for menuId in interceptor.
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
I think these parameters will get places into the request and can be retrieved from there. Also, if you make bean properties for these values in your action class I think they will be placed into the action class as well.
shashi wagh
Ranch Hand

Joined: Oct 30, 2008
Posts: 38
I am getting value in action class by getter and setter
but I want the value in Interceptor

even I have use

String menuId = request.getParameter( "menuID");

in my Interceptor.
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
Your intercept method should recieve a parameter of type ActionInvocation. If you call .getAction on this object you can get a reference to your action class and then you can get the values from there.
shashi wagh
Ranch Hand

Joined: Oct 30, 2008
Posts: 38
Thanks Tom it's working fine.
Krishnan Rathnakumar
Greenhorn

Joined: Mar 26, 2010
Posts: 5
Hi, shashi wagh

i need a example for what you got a solution, because i am also have a same problem.
how can i get a parameter values in interceptor.

please help me.

thanks in advance
Rajukpo kumar
Greenhorn

Joined: Dec 31, 2010
Posts: 9
Hi Krishnan,

You got any example regarding same..?

It will be very helpful if you could share that if so.

Thanks,
Raju.
Anirban Chowdhury
Ranch Hand

Joined: Aug 05, 2008
Posts: 36
Struts 2.0.11 version

MyInterceptor implements Interceptor , StrutsStatics{

public String intercept(ActionInvocation invocation) throws Exception {
final ActionContext context = invocation.getInvocationContext ();
HttpServletRequest request = (HttpServletRequest) context.get(HTTP_REQUEST);
Map params = request.getParameterMap();
//Retrieve the map and check..
for (Iterator iterator = params.keySet().iterator(); iterator.hasNext();) {
String key = (String) iterator.next();
String[] obj = (String[])(params.get(key));
if(obj.length>0)
System.out.println(key+"<>"+obj[0]);


}

}

To living life on the edge! I blog my experiences @ http://anirbanchowdhury.wordpress.com.
Rajukpo kumar
Greenhorn

Joined: Dec 31, 2010
Posts: 9
Hi Anirban,

Thanks for your reply...

I followed the way that i mentioned below.



Regards,
Raju
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts 2 passing parameter to interceptor