?
Solved

Pass parameters to Struts forward

Posted on 2003-12-19
6
Medium Priority
?
21,363 Views
Last Modified: 2012-06-27
I need to pass some parameters to my forward,like that:

            www.something/myapp/newslist.do?sysId=4

here is my action delaration:

        <action path="/newscreate"
              type="NewsCreateAction"
              name="newsForm">
              <forward name="success" path="/newslist.do"/>
        </action>

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

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.
0
Comment
Question by:dualsoul
  • 3
  • 2
6 Comments
 
LVL 92

Expert Comment

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

Accepted Solution

by:
TimYates earned 2000 total points
ID: 9975881
Hiya!

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

Tim
0
 
LVL 15

Author Comment

by:dualsoul
ID: 9977065
>  try setting redirect to false in your forward:
if it's false, i even can't point my browser to    ......../newslist.do?sysId=4

ohhh....it seems i need to examine Struts sources...hm...%-/
strange...so simple thing, and no support for it...
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 15

Author Comment

by:dualsoul
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){
            params.put(paramName,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();
            if(iter.hasNext()){
               //add first parameter, if avaliable
                  Map.Entry entry=(Map.Entry)iter.next();
                  path.append("?"+entry.getKey()+"="+entry.getValue());                  
               //add other parameters      
                  while(iter.hasNext()){
                        entry=(Map.Entry)iter.next();
                        path.append("&"+entry.getKey()+"="+entry.getValue());
                  }
            }
            
            return new ActionForward(path.toString());
      }      
}
.................................

and my life become much easier now :):
........................
            return new ForwardParameters().add("sysId","4")
                                          .add("id","5")
                                          .add("some","value")
                                          .forward(mapping.findForward("success"));
......................

Thans Tim.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9984065
Woo!  Nice wrapper :-)

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

Good luck!!

Tim
0
 
LVL 15

Author Comment

by:dualsoul
ID: 9984225
have a nice week :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

569 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