实例:
struts.xml的配置
<!-- 开启动态方法,value改为true -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<result name="success" type="redirectAction">${nextAction}</result> <!-- 权限分配 转到下一个action -->
</action>
<!-- 普通用户 -->
<action name="common">
<result>/page/house_list.jsp</result>
</action>
<!-- 管理员 -->
<action name="manager">
<result>/page/manage.jsp</result>
</action>
-------------------------------------------------------------------------------------------------------------
Action代码中的写法
增加:
private String nextAction; //下一个action的名字,用于实现动态结果的配置
public String getNextAction() {
return nextAction;
}
public void setNextAction(String nextAction) {
this.nextAction = nextAction;
}
登录方法的写法:
//登录
public String doLogin() throws UnsupportedEncodingException {
// 调用业务逻辑层
User temp = biz.login(user.getUserName(), user.getUserPass());
if (temp != null) {
if("1".equals(temp.getIsAdmin())){
nextAction = "common";
} else if("0".equals(temp.getIsAdmin())){
nextAction = "manager";
}
return "success";
}
return "error";
}