描述:设置Session属性。value参数可以为任何Java Object。通常为java Bean。value信息不宜过大
方法名:String getAttribute(String attribute)
描述:返回Session属性
描述:返回Session中存在的属性名
描述:移除Session属性
方法名:String getId()
描述:返回Session的ID。该ID由服务器自动创建,不会重复
方法名:long getCreationTime()
描述:返回Session的创建日期。返回类型为long,常被转化为Date类型,例如:Date createTime = new Date(session.get CreationTime())
方法名:long getLastAccessedTime()
描述:返回Session的最后活跃时间。返回类型为long
方法名:int getMaxInactiveInterval()
描述:返回Session的超时时间。单位为秒。超过该时间没有访问,服务器认为该Session失效
方法名:void setMaxInactiveInterval(int second)
描述:设置Session的超时时间。单位为秒
方法名:void putValue(String attribute, Object value)
描述:不推荐的方法。已经被setAttribute(String attribute, Object Value)替代
方法名:Object getValue(String attribute)
描述:不被推荐的方法。已经被getAttribute(String attr)替代
方法名:boolean isNew()
描述:返回该Session是否是新创建的
描述:使该Session失效
Tomcat中Session的默认超时时间为20分钟。通过setMaxInactiveInterval(int seconds)修改超时时间。可以修改web.xml改变Session的默认超时时间。例如修改为60分钟:
<session-config>
<session-timeout>60</session-timeout> <!-- 单位:分钟 -->
</session-config>