實例:
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";
}