struts控制器中使用new ActionForward和mapping.findForward的区别

struts控制器中使用new ActionForward和mapping.findForward的区别

request.setAttribute("list", new Integer(0));
                       return new ActionForward("/success.jsp");

request.setAttribute("list", new Integer(0));
   return mapping.findForward("fail");

当使用 return new ActionForward("/success.jsp");的时候相当于还是同一个request请求,所以可以携带参数setAttribute过去。
                            无论 <forward
                             name="succ"
                             path="/success.jsp"
                            redirect="true" />//无论此处的redirect是true还是false。

当使用 return mapping.findForward("fail");的时候如果 redirect="true",相当于还是另外一个request请求,所以不能携带参数setAttribute过去。
                 要想还是使用同一个request,获取到参数,则把
                                    <forward
                             name="succ"
                             path="/success.jsp"
                            redirect="false" />//此处的redirect改为false。另外,此处不设置的话默认redirect="false"。

无论在任何情况下使用
request.getSession().setAttribute("a", "sssss");都可以传递参数。
在页面处获取 <%=request.getSession().getAttribute

posted on 2011-02-18 16:27 小罗 阅读(2494) 评论(1)  编辑  收藏

评论

# re: struts控制器中使用new ActionForward和mapping.findForward的区别 2013-07-23 16:20 吃饭

回家哦那里呢  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
<2011年2月>
303112345
6789101112
13141516171819
20212223242526
272812345
6789101112

导航

统计

常用链接

留言簿

随笔分类

随笔档案

文章分类

文章档案

相册

收藏夹

Web Framework

常上的技术网站

查找资料的java网站

搜索

最新评论

阅读排行榜

评论排行榜