struts配置文件默认值及跳转Action的方法

一、Result:
Name属性默认值:”success”;
Type属性默认值:”dispatcher”
Redirect:重定向

<result name="input" type="redirect">index.jsp</result>

redirectAction:重定向Action:指向另一个actionName。

<result name="success" type="redirectAction">logoutUser</result>

二、还可以通过Action的属性存储下一个actionName,在result中通过表达式${属性名}动态获取目标Action。
1声明nextAuction,设置setter/getter方法

private String nextAuction;
public String getNextAuction() {
	return nextAuction;
}

public void setNextAuction(String nextAuction) {
	this.nextAuction = nextAuction;
}

2在login()方法中指定nextAuction

public String login() throws Exception {
		slist = new ArrayList<String>();
		slist.add("刘备");
		slist.add("孙权");
		slist.add("曹操");
		ulist=new ArrayList<User>();
		ulist.add(new User("刘备",38));
		ulist.add(new User("曹操",45));
		ulist.add(new User("孙权",27));
		
		msg = "welcome: " + userName;
		if (user.getUserName().equals("张三")) {
			Map<String, Object> session = ActionContext.getContext()
					.getSession();
			System.out.println(user.getUserName()+" "+user.getAge());
			session.put("currUser", user.getUserName());
			nextAuction="logoutUse+r";
			return "success";
		} else {

			return "error";
		}
	}

3在result中加入

<result name="success" type="redirectAction">${nextAuction}</result>

三、在跳转action时带上参数

在result中设置actionName和参数
<result name="success" type="redirectAction">
<param name="actionName">logoutUser</param>
<param name="userName">${user.userName}</param>
</result>

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值