首页 > 移动平台 > 详细

action访问servlet的API并且获取到MAP类型的application,session,request

时间:2017-01-12 18:06:54      阅读:16      评论:0      收藏:0      [点我收藏+]

标签:oid   实现   使用   ces   col   obj   out   .com   his   

public class testAction3 extends ActionSupport {
    
    private Map<String,Object> request;
    private Map<String,Object> session;
    private Map<String,Object> application;
    
    /**
     * 构造函数,没有返回值
     */
    public testAction3(){
        this.request=(Map) ActionContext.getContext().get("request");
        this.session=ActionContext.getContext().getSession();
        this.application=ActionContext.getContext().getApplication();
    }

    @Override
    public String execute(){
        System.out.println("开始。。。。");
        this.request.put("reqAttr","reqDirect");
        this.session.put("sessionAttr", "sessionDirect");
        this.application.put("appAttr", "appDirect");
        return SUCCESS;
    }

}
 <body>
    request:${reqAttr}<br>
    session:${sessionAttr}<br>
    application:${appAttr}<br>
    ------------------------------<br>
    request:${requestScope.reqAttr}<br>
    session:${sessionScope.sessionAttr}<br>
    application:${applicationScope.appAttr}<br>
  </body>

技术分享

或者使用IoC方法:需要实现相应的接口

public class testAction3 extends ActionSupport implements RequestAware,SessionAware,ApplicationAware{
    
    private Map<String,Object> request;
    private Map<String,Object> session;
    private Map<String,Object> application;
    
    @Override
    public void setApplication(Map<String, Object> application) {
        // TODO Auto-generated method stub
        this.application=application;
    }
    @Override
    public void setSession(Map<String, Object> session) {
        // TODO Auto-generated method stub
        this.session=session;
    }
    @Override
    public void setRequest(Map<String, Object> request) {
        // TODO Auto-generated method stub
        this.request=request;
    }

    @Override
    public String execute(){
        System.out.println("开始。。。。");
        this.request.put("reqAttr","reqDirect");
        this.session.put("sessionAttr", "sessionDirect");
        this.application.put("appAttr", "appDirect");
        return SUCCESS;
    }
}

 

action访问servlet的API并且获取到MAP类型的application,session,request

标签:oid   实现   使用   ces   col   obj   out   .com   his   

原文:http://www.cnblogs.com/-beauTiFul/p/6279137.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号