*
The moose likes Struts and the fly likes Struts: request parameters and ActionForms Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts: request parameters and ActionForms" Watch "Struts: request parameters and ActionForms" New topic
Author

Struts: request parameters and ActionForms

Rick DeBay
Ranch Hand

Joined: Jul 11, 2003
Posts: 70
My action is requests that contain parameters. Is there a way to get an ActionForm and the Validator to handle these, or do I need to just use HttpRequestServlet?
Thanks, Rick DeBay
sandy gupta
Ranch Hand

Joined: Jan 30, 2001
Posts: 228
What is it that we are doing here exactly? Can you be more detailed about it.


Adios
Rick DeBay
Ranch Hand

Joined: Jul 11, 2003
Posts: 70
Given a link:
http://localhost:8080/app/category-link.do?cid=11
my Action parses it thusly:
long catId = 0;
String categoryId = request.getParameter(ReqParams.CATEGORY_ID);
if (categoryId != null && categoryId.length() > 0)
{
try
{
catId = Long.parseLong(categoryId);
}
catch (NumberFormatException nfe)
{
}
}
if (catId > 0)
{
// do stuff
}
else
{
// error
}
I would like the validator to determine that the request parameter existed and was a valid long, instead of writing this myself. Or am I mistaken and is the ActionForm already handling this? Or does it only handle parameters submitted from a POST?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts: request parameters and ActionForms
 
Similar Threads
Context param values from web.xml
method-params problem
forwarding request to some other server
passing a single value from link to action class
Special characters with query string