File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Forwarding to another action with parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Forwarding to another action with parameter" Watch "Forwarding to another action with parameter" New topic

Forwarding to another action with parameter

Dan Gun

Joined: Aug 06, 2003
Posts: 26
How to forward to another action which requires parameter(s)?


For example:

SCJP 1.4
Shankar Narayana
Ranch Hand

Joined: Jan 08, 2003
Posts: 134
I am also trying the same, but coudn't work out yet, when I try to forward to a Action with more than one queryString parameter, it just displays to me that the page cannot be found.

Any ideas

"Failure is not when you fall down; its only when you fail to get up again."
Roel De Nijs

Joined: Jul 19, 2004
Posts: 8411

i did something like this:

hope this helps

SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
Prasanna Puttappa
Ranch Hand

Joined: Jul 21, 2003
Posts: 54
Try using setPath() method of ActionForward class. ActionForward inherits this method from ForwardConfig class.

Hope this will be helpful.


~Prasanna (SCJP5.0, SCWCD5)
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

You should always take care when forwarding from one action to another. The most common "bug" that arises from doing this is that of disappearing or overwritten form values (note the quotes). This is not actually a bug but normal behavior. You just need to understand what the framework is doing.

In the case of wanting to pass parameters when forwarding from one Action to another, my experience has been that this is usually a code smell. Code smells should result in refactoring to eliminate the code smell.

But first, why do you need to pass parameters to the second Action? Are the parameter values already in the ActionForm that Action 1 received with the current request? If that is the case, you don't need to do anything since the parameters are already in the request. Just make sure that the ActionForm associated with Action 2 has corresponding fields that will receive those parameters.

If the parameter values were not submitted with the request, I would say refactor and extract the code in Action 2 that uses the parameters. Put that code into a Helper class instead. Then you can use the Helper class from both Action 1 and Action 2 without having to go through the error-prone exercise of forwarding from one Action to another.

Junilu - [How to Ask Questions] [How to Answer Questions]
I agree. Here's the link:
subject: Forwarding to another action with parameter
It's not a secret anymore!