• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

parameters have to be class variables of Action class ?

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I created a struts 2 action class and proper mapping in struts.xml.

1) In my Action class, I have "name", "state", etc class variables.

execute() {
HttpServletRequest request = ServletActionContext.getRequest();
request.getAttribute("name");
....
}
2) action /myAction is mapped to this action class in struts.xml and it has

the method 'test()" is a json type

<result type="json">

Now,

I noticed when I access URL like

/myAction?name=john&state=ca

it works fine.

But if I try

/myAction?county=clouders

it fails in

request.getAttribute("county");

because it shows it can't find anything for "county" attribute ALTHOUGH I supplied it in the access URL.

If I am accessing a regular HttpServlet (instead of Astruts 2) then in servlet's "get" method I was able to get it. But in action class, why can my
HttpServletRequest only retrieve variables that are sdefined in the class ? Please help explain. Thanks.




 
Ranch Hand
Posts: 41
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly, was an attribute named 'county' set somewhere that you're trying to get through getAttribute method?

The part of the URL:


signifies county is a request parameter and NOT a request attribute. In Struts2, since you don't have an ActionForm, parameters and their getters/setters are coded in the Action class. I'd sugest understanding the differences between attributes and parametes in various scopes. These links could be helpful in understanding them:
Link1 (remove %20) in the URL.
Link2

Help us help you by providing us with actual error messages.
 
mark I thomas
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes "county" is passed as parameter. In this case, should the action class extends "ParamterAware" stuff ?
what's the syntax to retrieve this parameter value in action's method ?
 
Orton K Randy
Ranch Hand
Posts: 41
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't have to. I believe you had gone through the methods(well there's only one I believe) of ParameterAware. I'd recommend implementing ServletRequestAware instead which would give you the access to request object. You guessed it, there's ServletResponseAware and SessionAware interfaces too. Thing is the request(and response/session) object(s) would be injected through respective setters. This example should give you more insight into using these objects. Hope that helps.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic