struts重定向
来源:互联网 发布:查看内存软件 编辑:程序博客网 时间:2024/05/21 11:06
如在一个登录的action中验证成功后,重定向为显示用户信息的action: showInfo.do
一、在struts1 中实现:
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
//一些处理„„
//重定向
ActionForward forward = new ActionForward("showInfo.do");
forward.setRedirect(true);
return forward } }
二、在struts2 中,因为执行函数返回结果不再是ActionForward ,而是一个字符串,所以不能再像struts1中那样跳转了。
在struts2中,重定向要在struts.xml中配置:
<action name="login" class="LoginAction"><result name="success" type="velocity">/pages/logok.vm</result>
<result name="redirect_1" type="redirect">showInfo.do</result>
<result name="redirect_2" type="redirect">showInfo.do?name=yangzi</result>
<result name="redirect_3" type="redirect">showInfo.do?name=${name}</result>
<result name="redirect_4" type= "redirect">
<param name="actionName">showInfo</param>
<param name="name">${name}</param>
</result>
</action>
对应的LoginAction:
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String execute() throws Exception {
//一些处理„„
name=xiaowang //给要传递的参数赋值
return SUCCESS;
//默认页面 return "redirect_1"
//重定向(不带参数) showInfo.do
//return "redirect_2"
//重定向(带固定参数yangzi) showInfo.do?name=yangzi
//重定向(带动态参数,根据struts.xml的配置将${name}赋值为xiaowang)最后为 showInfo.do?name=xiaowang // return "redirect_3"//return "redirect_4" //这个是重定向到 一个action } }
三、说明
struts2 重定向分重定向到url和重定向到一个action。 实现重定向,需在struts.xml中定义返回结果类型。
type="redirect" 是重定向到一个URL。type="redirect-action" 是重定向到一个action。
参数也是在这里指定,action中所做的就是给参数赋值,并return 这个结果。
- Struts自定义重定向
- Struts重定向
- struts重定向
- Struts重定向Action方法
- struts-config.xml配置重定向
- struts配置文件重定向的问题
- struts重定向传值的方法
- Struts框架之转发和重定向
- struts 转发重定向 参数书写格式
- struts在代码中动态组装重定向请求
- struts学习第一天------action各种重定向
- struts result type redirect 重定向和转发的区别
- struts 重定向传参中文乱码问题解决方案
- 重定向
- 重定向
- 重定向
- 重定向
- 重定向
- Java主线程等待子线程执行完毕-CountDownLatch
- SharePoint 2013 Workflow Manager 工作流配置注意事项
- jboss部署web应用
- 倒排索引基础
- 【老邮记】《漫漫邮子路(六)--“三线”人的工作与爱情——王逢和》
- struts重定向
- linux crontab 定时命令
- 回文字符串数量
- 线程池的简单使用
- HDU 3339 In Action 最短路(dijkstra) + 裸01背包
- extjs grid 从json 获取动态列
- ceph主要数据结构解析3-Ceph_fs.h文件
- 项目中遇到的问题
- mysql数据类型详解