Topic: 请问Struts中如何给Redirect过去的Action传参数?

  Print this page

1.请问Struts中如何给Redirect过去的Action传参数? Copy to clipboard
Posted by: xinzi
Posted on: 2004-03-09 13:46

有两个Action

<action path="/app/a" type="Action_A"
......
>
<action path="/app/b" type="Action_B"
<forward name="success" path="/app/a.do" redirect="true"/>
>

现在在Action_B的代码中用return mapping.findForward("success");
实现/app/b.do转到/app/a.do的转向。

Action_A需要接受从表单(或url)中传来的参数才能正常运行。由于forward过去用了redirect="true",所以用request.setAttribute()方法,不能传参数,不知道这个参数如何传递,请大家帮忙。谢谢!

2.Re:请问Struts中如何给Redirect过去的Action传参数? [Re: xinzi] Copy to clipboard
Posted by: hitaco
Posted on: 2004-03-10 21:59

If redirect is used, all request scope data will be lost.

maybe you can configure your form in session scope.

Unlike "forward", redirect involves two HTTP request, since HTTP is stateless, request scope data will never be maintained between different user requests.

3.Re:请问Struts中如何给Redirect过去的Action传参数? [Re: xinzi] Copy to clipboard
Posted by: xinzi
Posted on: 2004-03-11 09:06

Hi thaks a lot!
I've solve the problem.

String path = mapping.findForward("success").getPath();

//TODO: 读取本Action所有的请求参数,将path重新构造,加上请求参数

ActionForward = new ActionForward(path);
forward.setRedirect(true);
return forward;


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923