Pass parameters to Struts forward

Posted on 2003-12-19
Last Modified: 2012-06-27
I need to pass some parameters to my forward,like that:


here is my action delaration:

        <action path="/newscreate"
              <forward name="success" path="/"/>

        <action path="/newslist"
              <forward name="success" path="/NewsSystem/newslist.jsp"/>

and here is my forward code in NewsCreateAction:
        //I want to add some parameters here
      // Forward control to the specified success URI
            return (mapping.findForward("success"));

...i did'nt find this in Struts docs, and i'm too lazy today
to dig Struts sources, it's a friday ;)

Crossposted in JSP.
Question by:dualsoul
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 92

Expert Comment

ID: 9975398
try setting redirect to false in your forward:
<forward name="success" path="/NewsSystem/newslist.jsp" redirect="false"/>
LVL 35

Accepted Solution

TimYates earned 500 total points
ID: 9975881

I was trying to do this too...with no  success...what I ended up doing was (I haven't got my source code here at home, so this will  be approximate):

    ActionMapping success = mapping.findForward("success") ;
    success = new ActionMapping( success.getPath() + "?sysid=" + sysid, success.getRedirect() ) ;
    return success ;

Hope that helps you with a solution, and I hope you find a nicer way to do it, as then I will use that way too ;-)

LVL 15

Author Comment

ID: 9977065
>  try setting redirect to false in your forward:
if it's false, i even can't point my browser to    ......../ seems i need to examine Struts simple thing, and no support for it...
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

LVL 15

Author Comment

ID: 9977138
hm...yeah...there no anything about it in Struts ;(
Tim, i believe you mean ActionForward not ActionMapping :)
I get the same answer from JSP guys.
So, i write simple wrapper class for it, like this :
import java.util.*;
import org.apache.struts.action.*;

*  Encupsulates parameters for ActionForward.
public class ForwardParameters{
      private Map params=new HashMap();
      public ForwardParameters add(String paramName,String paramValue){
            return this;
      * Add parameters to provided ActionForward
      * @param forward ActionForward to add parameters to
      * @return ActionForward with added parameters to URL
      public ActionForward forward(ActionForward forward){
            StringBuffer path=new StringBuffer(forward.getPath());
            Iterator iter=params.entrySet().iterator();
               //add first parameter, if avaliable
                  Map.Entry entry=(Map.Entry);
               //add other parameters      
            return new ActionForward(path.toString());

and my life become much easier now :):
            return new ForwardParameters().add("sysId","4")

Thans Tim.
LVL 35

Expert Comment

ID: 9984065
Woo!  Nice wrapper :-)

I think  I'll use that too :-)  Woo!

Good luck!!

LVL 15

Author Comment

ID: 9984225
have a nice week :)

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question