• 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

Getting "GET" parameter in my Action class

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well that must be very basic, but for some reason I haven't figured it out.

When I execute a action from a link "/dostuff.do?test=1", how to get the integer parameter value "test" in my action class.

So far I have done so, and it returns null:


[ April 29, 2006: Message edited by: Juhan Voolaid ]
[ April 29, 2006: Message edited by: Juhan Voolaid ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're close. Use getParameter instead of getAttribute. Since getParameter always returns a string, you will have to convert it to an int.

int test = Integer.parseInt(request.getParameter("test"));

Also, in Struts, if you've defined "test" as one of the properties of the ActionForm that goes with this action, you can get the value by using the ActionForm's getter:

test = myActionForm.getTest();
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx, but ActionForms are used for POST parameters right?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts will populate your ActionForm either way.. GET or POST.

Try it... you'll see.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic