码迷,mamicode.com
首页 > 其他好文 > 详细

struts2动态结果集

时间:2015-12-03 21:10:30      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

在struts.xml中配置:

<action name="login" class="cn.orlion.user.UserAction" method="login">
             <result>
                 ${r}
             </result>
         </action>

UserAction:

package cn.orlion.user;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport{
    
    private int type;
    
    private String r;
    
    public String login(){
        
        if (1 == type) r = "/a1.jsp";
        else if (2 == type) r = "/a2.jsp";
        return "success";
    }

    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;
    }
    
}

这样当访问http://localhost:8080/Struts2Demo/user/login.action?type=1时就会看到a1.jsp

访问...?type=2时就会看到a2.jsp了

struts.xml中${r} 实际是从Value Stack中取出r的值

struts2动态结果集

标签:

原文地址:http://www.cnblogs.com/orlion/p/5017545.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!