数据 保存在 session ThreadContextHolder.getSessionContext().setAttribute() package com.enation.framework.context.webcontext.impl; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.Hashtable; import java.util.Set; import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.enation.framework.context.webcontext.WebSessionContext; /** * @author kingapex */ public class WebSessionContextImpl implements WebSessionContext, Externalizable { private HttpSession session; private final Log logger=LogFactory.getLog(getClass()); // private SaveSessionAttributeCallBack callBackHandle; private Hashtable attributes; // private FrameworkSessionContextImpl sessionAttributeHolder; /* * (non-Javadoc) * * @see com.lenovo.labs.framework.util.sessioncontext.impl.FrameworkSessionContext#getSession() */ public HttpSession getSession() { return session; } /* * (non-Javadoc) * * */ public void setSession(HttpSession session) { if(logger.isDebugEnabled()){ logger.debug("set session "+ session); } this.session = session; this.attributes = (Hashtable) this.session .getAttribute(sessionAttributeKey); if (attributes == null) { attributes = new Hashtable(); this.onSaveSessionAttribute(); } } /* * (non-Javadoc) * * @see com.lenovo.labs.framework.util.sessioncontext.impl.FrameworkSessionContext#invalidateSession() */ public void invalidateSession() { // this.session.removeAttribute(sessionAttributeKey); this.session.invalidate(); // this.session = null; // this.sessionAttributeHolder = null; } // public FrameworkSessionContextImpl getSessionAttributeHolder() { // return sessionAttributeHolder; // } // public void setSessionAttributeHolder(FrameworkSessionContextImpl // sessionAttributeHolder) { // // this.sessionAttributeHolder = sessionAttributeHolder; // // this.sessionAttributeHolder.setCallBackHandle(this); // this.session.setAttribute(sessionAttributeKey, // sessionAttributeHolder); // } private void onSaveSessionAttribute() { this.session.setAttribute(sessionAttributeKey, attributes); } /* * (non-Javadoc) * * @see com.lenovo.labs.framework.util.sessioncontext.impl.FrameworkSessionContext#setAttribute(java.lang.String, * java.lang.Object) */ public void setAttribute(String name, Object value) { if(attributes!=null){ // if(logger.isDebugEnabled()){ // logger.debug("set attribute :"); // logger.debug("attributes=>"+attributes); // logger.debug("name=>"+name); // logger.debug("value=>"+value); // } attributes.put(name, value); onSaveSessionAttribute(); } } /* * (non-Javadoc) * * @see com.lenovo.labs.framework.util.sessioncontext.impl.FrameworkSessionContext#getAttribute(java.lang.String) */ public Object getAttribute(String name) { if(attributes!=null) return attributes.get(name); else return null; } /* * (non-Javadoc) * * @see com.lenovo.labs.framework.util.sessioncontext.impl.FrameworkSessionContext#getAttributeNames() */ public Set getAttributeNames() { return attributes.keySet(); } /* * (non-Javadoc) * * @see com.lenovo.labs.framework.util.sessioncontext.impl.FrameworkSessionContext#removeAttribute(java.lang.String) */ public void removeAttribute(String name) { attributes.remove(name); onSaveSessionAttribute(); } // public SaveSessionAttributeCallBack getCallBackHandle() { // return callBackHandle; // } // // public void setCallBackHandle(SaveSessionAttributeCallBack // callBackHandle) { // this.callBackHandle = callBackHandle; // } public void readExternal(ObjectInput input) throws IOException, ClassNotFoundException { attributes = (Hashtable) input.readObject(); } public void writeExternal(ObjectOutput output) throws IOException { output.writeObject(attributes); } public void destory() { this.attributes = null; this.session = null; } }
详细解决方案
数据 封存在 session
热度:636 发布时间:2012-09-04 14:19:30.0
相关解决方案
- hibernate 连接 oracle session 有关问题
- Servlet Session 购物车,该怎么解决
- Servlet Session 购物车解决办法
- ssh多数据库配置 如何get session
- hibernate中Query query=session.createQuery的有关问题
- CAPTCHA 模块中 ajax form 导致CAPTCHA session reuse attack detected异常,解决方法
- session 覆盖的有关问题 求高手
- Could not deserialize session data解决方法
- response.write(session.getAttribute("BranchName")提示异常
- JSP上if(trim(session.getAttribute("grade"))== "0") 多谢!
- jsp session 过期提示有关问题
- session.invalidate()无效解决办法
- null id in com.bsw.gms.hibernate.pojo.Score entry (don't flush the Session after an exception occurs,该怎么解决
- struts2关于request,session,application传值与显示的有关问题
- java ssh session NullPointerException,该怎么处理
- spring2.0+hibernate3.2中,oracle中产生大量的inactive session,怎么解决
- session 登录有关问题
- Cannot create a session after the response has been committed,该怎么解决
- org.hibernate.HibernateException: No Session found for current thread解决办法
- Cannot create a session after the response has been committed解决办法
- Struts2 的 Action 类里如何创建 session request response out 对象
- eclipse+jboss开发一个十分简单的远程无状态 Session Bean 时遇到的有关问题
- spring aop关于获取 session 有关问题
- Session 什么时候结束会话,怎么判断非正常登录
- WEB session 有关问题
- 一个纠结的有关问题-session
- 使用 StateServer 保存 Session,哪位高手用过啊
- Session.Remove()为啥不起作用
- session 没法自动注销
- 小弟新手 - Session 与 Cookies 用法