aspose file tools*
The moose likes Struts and the fly likes What could cause this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "What could cause this?" Watch "What could cause this?" New topic
Author

What could cause this?

A Harry
Ranch Hand

Joined: Jan 23, 2002
Posts: 124
My app submits a form that contains a text field called "firstfield".

In my action class I can retrieve it's value from the request object -

String firstTransfer = request.getParameter("firstfield");

This action is then forwarded to another action BUT this field (in fact every parameter read or not read) is now null!

Any ideas why this might happen?

The form is "multipart/form-data", could this be the reason? even though during this request no file is uploaded?

thanks

harry
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
What you're doing is called "action chaining" and it's not recommended. If you want to pass parameters on to another action, you have to re-send the parameters in the query string. Example:

String url = "myAction.do?firstfield="+request.getParameter("firstfield");
return new ActionMapping(url, false);

A better alternative would be to use an ActionForm bean and have Struts automatically populate the properties of the bean rather than reading the parameters. The ActionForm does get passed on to a second action without jumping through hoops.


Merrill
Consultant, Sima Solutions
A Harry
Ranch Hand

Joined: Jan 23, 2002
Posts: 124
thanks Merrill, adding it to the Form sorted it!

can I ask why chaining actions is not recommended? in fact if the action is forwarded what happens to the request parameters?
[ December 08, 2006: Message edited by: A Harry ]
 
jQuery in Action, 2nd edition
 
subject: What could cause this?