Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts: request parameters and ActionForms

 
Rick DeBay
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is it that we are doing here exactly? Can you be more detailed about it.
 
Rick DeBay
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic