struts2中的动态结果集
struts2中的动态结果集,举例说明:
1、 url中调用Action
http://localhost:8080/struts2_1700_DynamicResult/user?type=1
http://localhost:8080/struts2_1700_DynamicResult/user?type=2
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>${r}</result>
</action>
</package>
</struts>
3、 在UserAction中包括两个属性:type和r (程序如下所示)
package net.dreamcreating;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private int type;
private String r;
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getR() {
return r;
}
public void setR(String r) {
this.r = r;
}
@Override
public String execute() throws Exception {
if(type==1)
r = "/user_success.jsp";
else
r = "/user_error.jsp";
return SUCCESS;
}
}