这是我下面的代码,当我执行时它显示大小为 3,但是当我弹出对象时,我只得到 2 个对象。
import java.util.*;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String name;
public String execute() throws Exception {
ValueStack stack = ActionContext.getContext().getValueStack();
Map<String, Object> context = new HashMap<String, Object>();
context.put("key1", new String("This is key1"));
context.put("key2", new String("This is key2"));
context.put("key3", new String("This is key3"));
stack.push(context);
System.out.println("Size of the valueStack: " + stack.size());
for (int i = 0; i < stack.size(); i++) {
System.out.println(i + ": " + stack.pop().toString());
}
return "success";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
请解释一下我是否做错了?
Wnd 我想知道存储的对象是什么ValueStack
以及如何检索这些对象?