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"/>(可以獲取到值)