这个是tomcat6.x的源代码,

org.apache.catalina.session.StandardSession
使用如下的结构来存储session的值

protected Map attributes = new ConcurrentHashMap();


public void setAttribute(String name, Object value)
里,实际调用了
setAttribute(name,value,true);


public void setAttribute(String name, Object value, boolean notify)

里,如果value是0,则调用removeAttrbute方法,将属性移除

if (value == null) {
removeAttribute(name);
return;
}

否则调用

Object unbound = attributes.put(name, value);
将数值保存到里面,同时拿到以前的值



我们来看看
public void removeAttribute(String name, boolean notify)

调用了
protected void removeAttributeInternal(String name, boolean notify)

// Avoid NPE = NullPointerException 呵呵,就是空指针
if (name == null) return;

// Remove this attribute from our collection
// 就是简单的从Map里面删除
Object value = attributes.remove(name);

// 后面还有一些事件通知的方法调用



可见在Session里,我们常用的操作就是这么实现的,没有什么高深的东西。
只要我们能拿到属于我们的session对象,就可以拿到我们保存在里面的东西了。
快乐渡过每一天,减肥坚持每一天