带参数的结果集
结论:一次request有且只有一个值栈。所以在服务器端action之间互相forward的时候,可以共享参数,所以在服务器端跳转的时候不需要传递参数,但是在客户端跳转的时候需要传递相应的参数。
Struts.xml:
<action name="user" class="com.oristand.actions.UserAction">
<result type="redirect">/success.jsp?t=${type}</result>
</action>
UserAction.java:
package com.oristand.actions;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
private int type;
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
@Override
public String execute() throws Exception {
return SUCCESS;
}
}
Success.jsp:
from valueStack:<s:property value="t"/><br>//这里因为重定向的是jsp页面,而不是Action,所以不会产生value stack,所以这的值就为空
from applicationContext: <s:property value="#parameters.t"/>//
这里的值就不为空
<s:debug></s:debug>
访问属性的三种方式:
第一种:
<result type="redirect">/success.jsp?t=${type}</result>//注意不是EL表达式
第二种:
<s:property value="t"/>//访问value stack中的值
第三种:
<s:property value="#parameters.t"/>//访问application中的值
<s:property value="errors.name[1]"/>//<s:debug>中分为value Stack Contents和Stack Content,对于value Stack Contents中的Propert Name,可以通过名字(例如error直接访问),对于Stack Content中的内容,则必须通过#来访问,如#request
<s:debug></s:debug>//这个很重要,可以查看Action中的value stack,action中的error是一个map,数据结构的东西还是很重要!