Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

struts 2 passing parameter to interceptor

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tom it's working fine.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Krishnan,

You got any example regarding same..?

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

Thanks,
Raju.
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]);


}

}
 
Rajukpo kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anirban,

Thanks for your reply...

I followed the way that i mentioned below.



Regards,
Raju
 
I just had the craziest dream. This tiny ad was in it.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic