struts2中的使用BaseAction获取Session
package com.owen.ma; import java.util.Map; import org.apache.struts2.interceptor.RequestAware; import org.apache.struts2.interceptor.SessionAware; import com.opensymphony.xwork2.ActionSupport; public class BaseAction extends ActionSupport implements RequestAware , SessionAware { private Map<string, object=""> request; private Map<string, object=""> session; @Override public void setRequest(Map<string, object=""> request) { this.request = request; } @Override public void setSession(Map<string, object=""> session) { this.session = session; } public Object getAttribute(String key) { if (this.request.containsKey(key)) { return this.request.get(key); } return null; } public void setAttribute(String key, Object object) { if (this.request.containsKey(key)) { this.request.remove(key); this.request.put(key, object); } } public Object getSession(String key) { if (this.session.containsKey(key)) { return this.session.get(key); } return null; } public void setSession(String key, Object object) { if (this.session.containsKey(key)) { this.session.remove(key); this.session.put(key, object); } } }
作者:森林木马
-------------------------------------------
特此声明:所有评论和私信都会在第一时间回复。也欢迎朋友们指正错误,共同进步!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
个性签名:好记性不如勤随笔,好随笔还请多关注!