Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts 1.3 action forward parameter

I'm working on a little project which uses Struts 1.3 and I encountered the following problem.

After some business logic takes place in an Action i want to forward the control to another Action which is mapped in struts-config.xml.

Usually this is the way I'm solving this:

struts-config.xml

<action path="/boardCreate" type="com.example.BoardCreateAction" name="BoardCreateForm" input="/board.jsp">
    <forward name="success" path="/board.do" redirect="true" />
</action>

Java action class

return mapping.findForward("success");

This will take make a redirect to the board.do action which is also mapped there.

My problem is that I want to redirect the control to something like:

<forward name="success" path="/board.do?id=1" redirect="true" />

Notice the id=1 parameter. Is this any other way except rebuilding my own action forward for this? I can't find any documentation debating this matter. Thanks!

like image 309
TGM Avatar asked May 27 '12 17:05

TGM


People also ask

What is action forward in struts?

An ActionForward represents a destination to which the controller, RequestProcessor, might be directed to perform a RequestDispatcher. forward or HttpServletResponse. sendRedirect to, as a result of processing activities of an Action class.

What is parameter in struts config xml?

In Struts1 you can use the attribute parameter from element(struts-config. xml) and access it's value within the action class via the actionMapping. getParameter() method. For actions requiring multiple steps, the parameter is often used to indicate which step the mapping is associated with.

What is forward name in struts config xml?

<forward> name— The name of the forward to be performed. path— The full path to another action, local JSP page, or remote page.


1 Answers

ActionRedirect redirect = new ActionRedirect(mapping.findForward("success"));
redirect.addParameter("id", theId);
return redirect;

See http://tool.oschina.net/uploads/apidocs/struts-1.3.10/org/apache/struts/action/ActionRedirect.html

like image 54
JB Nizet Avatar answered Sep 19 '22 16:09

JB Nizet