• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can request in Struts' action get parameters from url?

 
Sean Li
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a link of this kind: test.do?action=create.
and in my testAction file, i wrote:
String action=request.getAttribute("action");
but later when i was using the variable action, the system tell me the action is null. why? i don't know how this comes.
so how can i get parameters from the url in Struts?
please help me, thanks!
 
Sean Li
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
should be:
String action=(String)req.getParameter("action");
 
Ron Ditch
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just add a string field to your view bean with the name of the URL parameter.
Struts will populate your form bean with the URL parameter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic