public class SessionImpl extends Object implements javax.servlet.http.HttpSession, Serializable, Session
HttpSession接口。
注意,每个request均会创建独立的session对象,此对象本身不是线程安全的,不能被多线程同时访问。但其后备的session store是线程安全的。
| Constructor and Description |
|---|
SessionImpl(String sessionID,
SessionWebContext webContext,
boolean isNew,
boolean create)
创建一个session对象。
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
assertAttributeNameForModification(String methodName,
String attrName)
检查将要更改的attr name是否合法。
|
protected void |
assertModel(String methodName)
确保model已经被取得,即session已被初始化。
|
protected void |
assertValid(String methodName)
确保session处于valid状态。
|
void |
clear()
清除一个session。
|
void |
commit(boolean commitHeaders)
提交session的内容,删除的、新增的、修改的内容被保存。
|
Object |
getAttribute(String name)
取得指定名称的attribute值。
|
Enumeration<String> |
getAttributeNames()
取得所有attributes的名称。
|
long |
getCreationTime()
取得session的创建时间。
|
String |
getId()
取得session ID。
|
long |
getLastAccessedTime()
取得最近访问时间。
|
int |
getMaxInactiveInterval()
取得session的最大不活动期限,超过此时间,session就会失效。
|
javax.servlet.ServletContext |
getServletContext()
取得当前session所属的servlet context。
|
javax.servlet.http.HttpSessionContext |
getSessionContext()
Deprecated.
no replacement
|
String |
getSessionID()
取得session ID。
|
SessionModel |
getSessionModel()
取得当前的model。
|
SessionWebContext |
getSessionWebContext()
取得创建该session的request context。
|
Object |
getValue(String name)
Deprecated.
use getAttribute instead
|
String[] |
getValueNames()
Deprecated.
use getAttributeNames instead
|
void |
invalidate()
使一个session作废。
|
boolean |
isExpired()
判断session有没有过期。
|
boolean |
isInvalidated()
判断当前session是否非法。
|
boolean |
isNew()
当前session是否为新的?
|
void |
putValue(String name,
Object value)
Deprecated.
use setAttribute instead
|
void |
removeAttribute(String name)
删除一个attribute。
|
void |
removeValue(String name)
Deprecated.
use removeAttribute instead
|
void |
setAttribute(String name,
Object value)
设置指定名称的attribute值。
|
void |
setMaxInactiveInterval(int maxInactiveInterval)
设置session的最大不活动期限,超过此时间,session就会失效。
|
String |
toString() |
public SessionImpl(String sessionID, SessionWebContext webContext, boolean isNew, boolean create)
public SessionWebContext getSessionWebContext()
public SessionModel getSessionModel()
public String getId()
getId in interface javax.servlet.http.HttpSessionpublic long getCreationTime()
getCreationTime in interface javax.servlet.http.HttpSessiongetCreationTime in interface SessionIllegalStateException - 如果session已经invalidatedpublic long getLastAccessedTime()
getLastAccessedTime in interface javax.servlet.http.HttpSessiongetLastAccessedTime in interface SessionIllegalStateException - 如果session已经invalidatedpublic int getMaxInactiveInterval()
getMaxInactiveInterval in interface javax.servlet.http.HttpSessiongetMaxInactiveInterval in interface Sessionpublic void setMaxInactiveInterval(int maxInactiveInterval)
setMaxInactiveInterval in interface javax.servlet.http.HttpSessionmaxInactiveInterval - 不活动期限的秒数public String getSessionID()
SessiongetSessionID in interface Sessionpublic boolean isExpired()
Sessionpublic javax.servlet.ServletContext getServletContext()
getServletContext in interface javax.servlet.http.HttpSessionServletContext对象public Object getAttribute(String name)
getAttribute in interface javax.servlet.http.HttpSessionname - attribute名称IllegalStateException - 如果session已经invalidatedpublic Enumeration<String> getAttributeNames()
getAttributeNames in interface javax.servlet.http.HttpSessionIllegalStateException - 如果session已经invalidatedpublic void setAttribute(String name, Object value)
setAttribute in interface javax.servlet.http.HttpSessionname - attribute名称value - attribute的值IllegalStateException - 如果session已经invalidatedIllegalArgumentException - 如果指定的attribute名称不被支持public void removeAttribute(String name)
removeAttribute in interface javax.servlet.http.HttpSessionname - 要删除的attribute名称IllegalStateException - 如果session已经invalidatedpublic void invalidate()
invalidate in interface javax.servlet.http.HttpSessioninvalidate in interface SessionIllegalStateException - 如果session已经invalidatedpublic void clear()
IllegalStateException - 如果session已经invalidatedpublic boolean isInvalidated()
public boolean isNew()
isNew in interface javax.servlet.http.HttpSessiontrueIllegalStateException - 如果session已经invalidatedprotected void assertModel(String methodName)
methodName - 当前正要执行的方法protected void assertValid(String methodName)
methodName - 当前正要执行的方法protected void assertAttributeNameForModification(String methodName, String attrName)
public void commit(boolean commitHeaders)
@Deprecated public javax.servlet.http.HttpSessionContext getSessionContext()
getSessionContext in interface javax.servlet.http.HttpSession@Deprecated public Object getValue(String name)
getValue in interface javax.servlet.http.HttpSession@Deprecated public String[] getValueNames()
getValueNames in interface javax.servlet.http.HttpSession@Deprecated public void putValue(String name, Object value)
putValue in interface javax.servlet.http.HttpSession@Deprecated public void removeValue(String name)
removeValue in interface javax.servlet.http.HttpSessionCopyright © 2006–2018 TinyGroup. All rights reserved.