类 MockHttpSession
- java.lang.Object
- org.springframework.mock.web.MockHttpSession
- 所有已实现的接口:
HttpSession
public class MockHttpSession extends Object implements HttpSession
Mock implementation of theHttpSession
interface.As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline.
Used for testing the web framework; also useful for testing application controllers.
- 从以下版本开始:
- 1.0.2
- 作者:
- Juergen Hoeller, Rod Johnson, Mark Fisher, Sam Brannen
字段概要
字段 修饰符和类型 字段 说明 static String
SESSION_COOKIE_NAME
构造器概要
构造器 构造器 说明 MockHttpSession()
Create a new MockHttpSession with a defaultMockServletContext
.MockHttpSession(ServletContext servletContext)
Create a new MockHttpSession.MockHttpSession(ServletContext servletContext, String id)
Create a new MockHttpSession.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
access()
String
changeSessionId()
As of Servlet 3.1, the id of a session can be changed.void
clearAttributes()
Clear all of this session's attributes.void
deserializeState(Serializable state)
Deserialize the attributes of this session from a state object created byserializeState()
.Object
getAttribute(String name)
Enumeration<String>
getAttributeNames()
long
getCreationTime()
String
getId()
long
getLastAccessedTime()
int
getMaxInactiveInterval()
ServletContext
getServletContext()
HttpSessionContext
getSessionContext()
Object
getValue(String name)
String[]
getValueNames()
void
invalidate()
Invalidates this session then unbinds any objects bound to it.boolean
isInvalid()
boolean
isNew()
void
putValue(String name, Object value)
void
removeAttribute(String name)
void
removeValue(String name)
Serializable
serializeState()
Serialize the attributes of this session into an object that can be turned into a byte array with standard Java serialization.void
setAttribute(String name, Object value)
void
setMaxInactiveInterval(int interval)
void
setNew(boolean value)
字段详细资料
SESSION_COOKIE_NAME
public static final String SESSION_COOKIE_NAME
- 另请参阅:
- 常量字段值
构造器详细资料
MockHttpSession
public MockHttpSession()
Create a new MockHttpSession with a defaultMockServletContext
.- 另请参阅:
MockServletContext
MockHttpSession
public MockHttpSession(ServletContext servletContext)
Create a new MockHttpSession.- 参数:
servletContext
- the ServletContext that the session runs in
MockHttpSession
public MockHttpSession(ServletContext servletContext, String id)
Create a new MockHttpSession.- 参数:
servletContext
- the ServletContext that the session runs inid
- a unique identifier for this session
方法详细资料
getCreationTime
public long getCreationTime()
- 指定者:
getCreationTime
在接口中HttpSession
getId
public String getId()
- 指定者:
getId
在接口中HttpSession
changeSessionId
public String changeSessionId()
As of Servlet 3.1, the id of a session can be changed.- 返回:
- the new session id
- 从以下版本开始:
- 4.0.3
access
public void access()
getLastAccessedTime
public long getLastAccessedTime()
- 指定者:
getLastAccessedTime
在接口中HttpSession
getServletContext
public ServletContext getServletContext()
- 指定者:
getServletContext
在接口中HttpSession
setMaxInactiveInterval
public void setMaxInactiveInterval(int interval)
- 指定者:
setMaxInactiveInterval
在接口中HttpSession
getMaxInactiveInterval
public int getMaxInactiveInterval()
- 指定者:
getMaxInactiveInterval
在接口中HttpSession
getSessionContext
public HttpSessionContext getSessionContext()
- 指定者:
getSessionContext
在接口中HttpSession
getAttribute
public Object getAttribute(String name)
- 指定者:
getAttribute
在接口中HttpSession
getValue
public Object getValue(String name)
- 指定者:
getValue
在接口中HttpSession
getAttributeNames
public Enumeration<String> getAttributeNames()
- 指定者:
getAttributeNames
在接口中HttpSession
getValueNames
public String[] getValueNames()
- 指定者:
getValueNames
在接口中HttpSession
setAttribute
public void setAttribute(String name, Object value)
- 指定者:
setAttribute
在接口中HttpSession
putValue
public void putValue(String name, Object value)
- 指定者:
putValue
在接口中HttpSession
removeAttribute
public void removeAttribute(String name)
- 指定者:
removeAttribute
在接口中HttpSession
removeValue
public void removeValue(String name)
- 指定者:
removeValue
在接口中HttpSession
clearAttributes
public void clearAttributes()
Clear all of this session's attributes.
invalidate
public void invalidate()
Invalidates this session then unbinds any objects bound to it.- 指定者:
invalidate
在接口中HttpSession
- 抛出:
IllegalStateException
- if this method is called on an already invalidated session
isInvalid
public boolean isInvalid()
setNew
public void setNew(boolean value)
isNew
public boolean isNew()
- 指定者:
isNew
在接口中HttpSession
serializeState
public Serializable serializeState()
Serialize the attributes of this session into an object that can be turned into a byte array with standard Java serialization.- 返回:
- a representation of this session's serialized state
deserializeState
public void deserializeState(Serializable state)
Deserialize the attributes of this session from a state object created byserializeState()
.- 参数:
state
- a representation of this session's serialized state