您的位置:首页 > 编程语言 > Java开发

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

2017-01-05 21:42 579 查看
一、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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  struts
相关文章推荐