java学习

java学习

 

struts2中四种实现request,session,application的方法

第一种
public class UserAction extends ActionSupport{

 /**
  *
  */
 private static final long serialVersionUID = 1L;
 private String name;
 private Map session;
 private Map request;
 private Map application;
 @Override
 public String execute() throws Exception {
  session =  ActionContext.getContext().getSession();
  request = (Map) ActionContext.getContext().get("request");
  application =  ActionContext.getContext().getApplication();
  session.put("sk", "sv");
  request.put("rk", "rv");
  application.put("ak", "av");
  System.out.println(name);
  return ActionSupport.SUCCESS;
  
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }

}


第二种

public class DepAction extends ActionSupport implements RequestAware,SessionAware,ApplicationAware{

 private Map<String, Object> request;
 private Map<String, Object> session;
 private Map<String, Object> application;
 
 
 public void setRequest(Map<String, Object> request) {
  this.request = request;
  
 }

 public void setSession(Map<String, Object> session) {
  this.session = session;
  
 }

 public void setApplication(Map<String, Object> application) {
  this.application = application;
  
 }

}


第三种

public class CarAction implements ServletRequestAware{
 private HttpServletRequest request;
 private HttpSession session;
 private ServletContext application;

 public void setServletRequest(HttpServletRequest request) {
  this.request = request;
  this.session = request.getSession();
  this.application = session.getServletContext();
  
 }

}


第四种

public class HomeAction extends ActionSupport{
 
 private HttpServletRequest request;
 private HttpSession session;
 private ServletContext application;

 public HomeAction (){
  request = ServletActionContext.getRequest();
  session = request.getSession();
  application = session.getServletContext();
}

}

posted on 2013-04-13 09:49 杨军威 阅读(168) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜