ActionForward-动态转发
来源:互联网 发布:php获取淘宝商品详情 编辑:程序博客网 时间:2024/04/29 16:00
ActionForward的作用就是从一个页面链接到另一个页面,最简单的应用就是mapping.findForward("success")。
属性:name-逻辑名称;path-URL;redirect-当设置为true是,重定向,默认为false;className(可选)-默认为ActionForward。
一般的调用过程:当ActionServlet调用Action时,Action 把Mapping的findForward()传递给它。findForward()先在局部转发列表中寻找key,如果没找到,再从全局转发列表中寻找。如果都没找到,此方法将返回null,浏览器报错。
在<html:link>标记中的使用:
在配置文件中定义一个forward: <forward name="article" path="/do/article?dispatch=view"/>
<html:link>中: <html:link forward="article" paramName="articleForm" paramProperty="articleKey" paramId="key">
News from the edge
</html:link>
运行结果: <a href="http://localhost/artimus/do/article?dispatch=view&key=17">News from the edge</a>
注意这边,如果已经存在一个参数,标签会很聪明的帮你添加一个连接符号,之后再添加参数。
添加自己要转发的路径: public ActionForward execute( ActionMapping mapping,ActionForm form, HttpServletRequest request,
HttpServletResponse response ) throws Exception{
ActionForward forward = new ActionForward();
String loginid = ((LoginForm)form).getLoginid();
String password = ((LoginForm)form).getPassword();
if(...){
...... // business code
forward.setPath("welcome.jsp");
}else{
ActionMessages errors = new ActionMessages();
.......
forward = mapping.findForward("Failure");
}
return forward;
}
HttpServletResponse response ) throws Exception{
ActionForward forward = new ActionForward();
String loginid = ((LoginForm)form).getLoginid();
String password = ((LoginForm)form).getPassword();
if(...){
...... // business code
forward.setPath("welcome.jsp");
}else{
ActionMessages errors = new ActionMessages();
.......
forward = mapping.findForward("Failure");
}
return forward;
}
在Action 类中添加参数: ActionForward forward = mapping.findForward("article");
StringBuffer path = new StringBuffer(forward.getPath());
boolean isQuery = (path.indexOf("?")>=0);
if (isQuery)
path.append("&dispatch=view");
else
path.append("?dispatch=view");
return new ActionForward(path.toString());
StringBuffer path = new StringBuffer(forward.getPath());
boolean isQuery = (path.indexOf("?")>=0);
if (isQuery)
path.append("&dispatch=view");
else
path.append("?dispatch=view");
return new ActionForward(path.toString());
如果ActionForward 没有设置为重定向,新的参数将被合并到当前request的参数中。如果新的参数的名称和原参数名称相同,在新的转发期内将使用新的参数值。
- ActionForward-动态转发
- ActionForward-动态转发
- ActionForward动态转发
- 动态ActionForward
- Struts页面转发控制ActionForward和ActionMapping
- 为ActionForward添加动态参数
- ActionForward
- ActionForward
- ActionForward
- ActionForward
- ActionForward
- ActionForward
- struts的action中使用ActionForward来转发,redirect
- new ActionForward和mapping.findForward(请求重定向和转发)
- 在Struts开发中,给ActionForward动态添加参数
- 1.Struts访问受保护的页面,动态ActionForward:界面
- 2.Struts访问受保护的页面,动态ActionForward:ActionForm
- 3.Struts访问受保护的页面,动态ActionForward:Action
- 如何理解Move参数中的const Source和var Dest
- 关于函数调用中形参的分析
- csdn的评论计数器又有bug了?
- ASP.NET程序中常用的三十三种代码
- don't cry
- ActionForward-动态转发
- struts系列学习(html标签库)
- struts系列学习(bean标签库)
- struts系列学习(logic标签库)
- 转载 熊猫烧香源码
- struts系列学习(tiles标签库一)
- Flash3Dbanner开发中
- 条件编译
- struts系列学习(tiles标签库二)