Pass parameters to Struts forward

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.
LVL 15
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
try setting redirect to false in your forward:
<forward name="success" path="/NewsSystem/newslist.jsp" redirect="false"/>

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 ;-)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dualsoulAuthor Commented:
>  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...
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

dualsoulAuthor Commented:
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.
Woo!  Nice wrapper :-)

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

Good luck!!

dualsoulAuthor Commented:
have a nice week :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.