input.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="deal2.action">点击跳转</a>
</body>
</html>
out.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>调用ValueStack本身的方法</h1>
<s:debug></s:debug><br>
<%-- <s:property value="user.name"/><br>
<s:property value="user.password"/><br> --%>
username:<s:property value="name"/><br>
password:<s:property value="password"/><br>
<h1>set方法</h1>
<s:property value="name"/><br>
</body>
</html>
struts.xml
<action name="deal2" class="Action.deal2">
<result>/值栈的操作out.jsp</result>
</action>
Action.java
package Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.util.ValueStack;
import bean.User;
public class deal2 extends ActionSupport {
@Override
public String execute() throws Exception {
//向值栈中保存数据:
//会的值栈对象:
ValueStack valueStack=ActionContext.getContext().getValueStack();
//使用push(Object obj); set(String key,Object obj);
User user=new User("老马","666");
//现在user在站定位置
valueStack.push(user);
valueStack.set("name", "老池"); //创建一个Map集合,将Map压入到栈中
return SUCCESS;
}
}
bean.java
package bean;
public class User {
private String name;
private String password;
public User(String name,String password) {
this.name=name;
this.password=password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}