动态结果配置:struts.xml中,属性的type配置之redirectAction(请求重定向到指定的Action)

  实例:

    struts.xml的配置

    <!-- 开启动态方法,value改为true -->
    <constant name="struts.enable.DynamicMethodInvocation" value="true" />


        <action name="login" class="com.house.action.UserAction" method="doLogin">
            <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";
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章