struts2中的带参数的结果集
struts2中如果是redirect跳转,需要传递参数时:
1、 url中调用Action
http://localhost:8080/struts2_1800_ResultWithParams/user.action?type=1
2、 struts.xml配置文件:
<struts>
<!-- Add packages here -->
<constant name="struts.devMode" value="true" />
<package name="resultType" namespace="/" extends="struts-default">
<action name="user" class="net.dreamcreating.UserAction">
<result type="redirect">/user_success.jsp?t=${type}</result>
</action>
</package>
</struts>
3、 在UserAction中包括属性:type (程序如下所示)
package net.dreamcreating;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private int type;
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
@Override
public String execute() throws Exception {
return SUCCESS;
}
}
4、 在user_success.jsp页面中获取t的值:
从值栈取值:<s:property value="t"/><br/>(获取不到值)
从actioncontext中取值:<s:property value="#parameters.t"/>(可以获取到值)