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;
}
}
本文详细介绍了Struts2中的动态结果集概念,通过URL调用Action,并配置struts.xml实现不同类型的动态结果,同时展示了如何在UserAction类中根据参数类型返回不同结果页面。
struts2中的动态结果集&spm=1001.2101.3001.5002&articleId=6849760&d=1&t=3&u=1e5fe46de8734986afaf702b035f110d)
1988

被折叠的 条评论
为什么被折叠?



