<!-- -->
|
JavaTM 2 Platform Ent. Ed. v1.4 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES <!-- if(window==top) { document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> All Classes <noscript></noscript> | |||||||
SUMMARY:NESTED|FIELD|CONSTR|METHOD | DETAIL:FIELD|CONSTR|METHOD |
Provides a way to identify a user across more than one page request or visit to a Web site and to store information about that user. 提供了一种方式来标识跨越多个页面请求或访问网站的用户,存储用户的相关信息。
The servlet container uses this interface to create a session between an HTTP client and an HTTP server. The session persists for a specified time period, across more than one connection or page request from the user. A session usually corresponds to one user, who may visit a site many times. The server can maintain a session in many ways such as using cookies or rewriting URLs. servlet容器利用该接口创建位于HTTP客户端和HTTP服务器之间的会话。会话将保持指定的时间段,跨越多个连接或者来自用户的页面请求。会话通常相当于一个多次访问某个网址的用户。服务器可以使用多种方式来维护会话,比如使用cookies或重写URL。
This interface allows servlets to 该接口允许servlet
When an application stores an object in or removes an object from a session, the session checks whether the object implements HttpSessionBindingListener
. If it does, the servlet notifies the object that it has been bound to or unbound from the session. Notifications are sent after the binding methods complete. For session that are invalidated or expire, notifications are sent after the session has been invalidatd or expired. 当应用在会话中存储或者从会话中删除一个对象,会话将检查对象是否实现HttpSessionBindingListener。如果是,servlet通知会话中绑定或者解除绑定的对象。通知在绑定(解除绑定)完成后发送。对于无效或过期的会话,通知将在会话无效或过期后发送。
When container migrates a session between VMs in a distributed container setting, all session attributes implementing the HttpSessionActivationListener
interface are notified. 当容器在分布式容器环境虚拟机中迁移会话,所有实现HttpSessionActivationListener接口的 会话属性将被通知。
A servlet should be able to handle cases in which the client does not choose to join a session, such as when cookies are intentionally turned off. Until the client joins the session, isNew
returns true
. If the client chooses not to join the session, getSession
will return a different session on each request, and isNew
will always return true
. servlet应当能够处理客户端没有选择加入会话这种情况,比如cookies被故意关掉。除非客户端加入会话,isNew返回true。如果客户端选择不加入会话,
Session information is scoped only to the current web application (ServletContext
), so information stored in one context will not be directly visible in another. 会话信息只在当前web应用中有效(ServletContext),因此存储在上下文中的信息对于另一个应用不能直接可见。
HttpSessionBindingListener
,
HttpSessionContext
<!-- ======== NESTED CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><!-- ======== CONSTRUCTOR SUMMARY ======== --><!-- ========== METHOD SUMMARY =========== --><!-- -->
Method Summary | |
Object |
getAttribute(Stringname) Returns the object bound with the specified name in this session, or null if no object is bound under the name. 返回session中指定名称的绑定对象,如果没有对象被绑定,返回null。 |
Enumeration |
getAttributeNames() Returns an Enumeration of String objects containing the names of all the objects bound to this session. 以String对象的枚举形式返回绑定给该session的所有对象名称。 |
long |
getCreationTime() Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.返回session创建的时间,以1970年1月1日0点为起点。 |
String |
getId() Returns a string containing the unique identifier assigned to this session. 返回一字符串,表示分配给session的唯一的标识符。 |
long |
getLastAccessedTime() Returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT, and marked by the time the container received the request. 返回上一次该会话相关的客户端请求时间,表示为从GMT 1970年1月1日以来的毫秒值,标记为容器接收到请求的时间。 |
int |
getMaxInactiveInterval() Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses. 以秒为单位返回最大间隔时间,在客户端访问之间servlet容器将保持会话开启。 |
ServletContext |
getServletContext() Returns the ServletContext to which this session belongs. 返回session属于的ServletContext。 |
HttpSessionContext |
getSessionContext() Deprecated.As of Version 2.1, this method is deprecated and has no replacement. It will be removed in a future version of the Java Servlet API. 从版本2.1以来,该方法不再支持,且没有替代方法。在Java Servlet API的以后版本中将被删除。 |
Object |
getValue(Stringname) Deprecated.As of Version 2.2, this method is replaced by getAttribute(java.lang.String) . 从版本2.2以来,该方法被getAttribute(java.lang.String)所替代。 |
String[] |
getValueNames() Deprecated.As of Version 2.2, this method is replaced by getAttributeNames() 从版本2.2以来,该方法被getAttributeNames()所替代。 |
void |
invalidate() Invalidates this session then unbinds any objects bound to it. 使session无效,解除所有对象的绑定。 |
boolean |
isNew() Returns true if the client does not yet know about the session or if the client chooses not to join the session. 如果客户端不知道该会话或者没有选择加入该会话,返回true。 |
void |
putValue(Stringname, Objectvalue) Deprecated.As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.Object) 从版本2.2以来,该方法被setAttribute(java.lang.String, java.lang.Object)所替代。 |
void |
removeAttribute(Stringname) Removes the object bound with the specified name from this session. 从session中删除指定名称绑定的对象。 |
void |
removeValue(Stringname) Deprecated.As of Version 2.2, this method is replaced by removeAttribute(java.lang.String) 从版本2.2以来,该方法被removeAttribute(java.lang.String)所替代。 |
void |
setAttribute(Stringname, Objectvalue) Binds an object to this session, using the name specified. 使用指定名称,向session绑定一个对象。 |
void |
setMaxInactiveInterval(intinterval) Specifies the time, in seconds, between client requests before the servlet container will invalidate this session. 以秒为单位指定servlet容器使会话失效之前客户端请求之间的间隔时间。 |
<!-- ============ FIELD DETAIL =========== --><!-- ========= CONSTRUCTOR DETAIL ======== --><!-- ============ METHOD DETAIL ========== --><!-- -->
Method Detail |
public long getCreationTime()
long
specifying when this session was created, expressed in milliseconds since 1/1/1970 GMT long值,表示上一次该会话创建的时间,即从GMT 1970年1月1日以来的毫秒值
IllegalStateException
- if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出
public String getId()
IllegalStateException
- if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出
public long getLastAccessedTime()
Actions that your application takes, such as getting or setting a value associated with the session, do not affect the access time. 应用程序执行的动作,比如获取或设置会话的相关值,不影响访问时间。
long
representing the last time the client sent a request associated with this session, expressed in milliseconds since 1/1/1970 GMT long值,表示上一次该会话相关的客户端请求时间,即从GMT 1970年1月1日以来的毫秒值
IllegalStateException
- if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出
public ServletContext getServletContext()
public void setMaxInactiveInterval(intinterval)
interval
- An integer specifying the number of seconds 整数,表示秒数
public int getMaxInactiveInterval()
setMaxInactiveInterval
method. A negative time indicates the session should never timeout. 以秒为单位返回最大间隔时间,在客户端访问之间servlet容器将保持会话开启。 在间隔之后,servlet容器将使会话失效。最大间隔值可以通过setMaxInactiveInterval方法设置。
setMaxInactiveInterval(int)
public HttpSessionContext getSessionContext()
public Object getAttribute(Stringname)
null
if no object is bound under the name. 返回session中指定名称的绑定对象,如果没有对象被绑定,返回null。
name
- a string specifying the name of the object 指定对象名称的字符串
IllegalStateException
- if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出
public Object getValue(Stringname)
getAttribute(java.lang.String)
. 从版本2.2以来,该方法被getAttribute(java.lang.String)所替代。
name
- a string specifying the name of the object 指定对象名称的字符串
IllegalStateException
- if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出
public Enumeration getAttributeNames()
Enumeration
of
String
objects containing the names of all the objects bound to this session. 以String对象的枚举形式返回绑定给该session的所有对象名称。
Enumeration
of
String
objects specifying the names of all the objects bound to this session String对象的枚举形式,表示绑定给该session的所有对象名称。
IllegalStateException
- if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出
public String[] getValueNames()
getAttributeNames()
从版本2.2以来,该方法被getAttributeNames()所替代。
String
objects specifying the names of all the objects bound to this session 表示会话绑定的所有对象名称的String对象数组
IllegalStateException
- if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出
public void setAttribute(Stringname, Objectvalue)
After this method executes, and if the new object implements HttpSessionBindingListener
, the container calls HttpSessionBindingListener.valueBound
. The container then notifies any HttpSessionAttributeListener
s in the web application. 在方法执行之后,如果对象实现了HttpSessionBindingListener,那么容器调用HttpSessionBindingListener.valueBound。 容器通知web应用中的所有HttpSessionAttributeListener。
If an object was already bound to this session of this name that implements HttpSessionBindingListener
, its HttpSessionBindingListener.valueUnbound
method is called. 如果已用该名称绑定给session的原对象实现HttpSessionBindingListener,那么调用HttpSessionBindingListener.valueUnbound方法。
If the value passed in is null, this has the same effect as calling removeAttribute()
. 如果值传递为null,那么效果与调用removeAttribute()相同。
Parameters:
name
- the name to which the object is bound; cannot be null 对象要绑定的名称,不能为null
value
- the object to be bound 要绑定的对象
Throws:
IllegalStateException
- if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出
<!-- -->putValue
public void putValue(Stringname,
Objectvalue)
Deprecated.
As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.Object)
从版本2.2以来,该方法被setAttribute(java.lang.String, java.lang.Object)所替代。
Parameters:
name
- the name to which the object is bound; cannot be null 对象要绑定的名称,不能为null
value
- the object to be bound; cannot be null 要绑定的对象,不能为null
Throws:
IllegalStateException
- if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出
<!-- -->removeAttribute
public void removeAttribute(Stringname)
Removes the object bound with the specified name from this session. If the session does not have an object bound with the specified name, this method does nothing. 从session中删除指定名称绑定的对象。如果session中不含指定名称的绑定对象,那么方法不做任何事。
After this method executes, and if the object implements HttpSessionBindingListener
, the container calls HttpSessionBindingListener.valueUnbound
. The container then notifies any HttpSessionAttributeListener
s in the web application. 在方法执行之后,如果对象实现了HttpSessionBindingListener,那么容器调用HttpSessionBindingListener.valueUnbound。 容器通知web应用中的所有HttpSessionAttributeListener。
Parameters:
name
- the name of the object to remove from this session 要从session中删除的对象名称
Throws:
IllegalStateException
- if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出
<!-- -->removeValue
public void removeValue(Stringname)
Deprecated.
As of Version 2.2, this method is replaced by removeAttribute(java.lang.String)
从版本2.2以来,该方法被removeAttribute(java.lang.String)所替代。
Parameters:
name
- the name of the object to remove from this session 要从session中删除的对象名称
Throws:
IllegalStateException
- if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出
<!-- -->invalidate
public void invalidate()
Invalidates this session then unbinds any objects bound to it. 使session无效,解除所有对象的绑定。
Throws:
IllegalStateException
- if this method is called on an already invalidated session 如果方法调用是基于一个已经无效的会话则抛出
<!-- -->isNew
public boolean isNew()
Returns
true
if the client does not yet know about the session or if the client chooses not to join the session. For example, if the server used only cookie-based sessions, and the client had disabled the use of cookies, then a session would be new on each request. 如果客户端不知道该会话或者没有选择加入该会话,返回true。比如,如果服务器使用基于cookie的会话, 客户端不能禁用cookies,那么会话对于每一个请求将是新的。
Returns:
true
if the server has created a session, but the client has not yet joined 如果服务器创建了一个会话,但是客户端还没有加入,返回true
Throws:
IllegalStateException
- if this method is called on an already invalidated session 如果方法调用是基于一个已经无效的会话则抛出
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== --><!-- -->
<!-- -->
Overview
Package
Class
Tree
Deprecated
Index
Help
JavaTM 2 Platform
Ent. Ed. v1.4
PREV CLASS NEXT CLASS
FRAMES NO FRAMES <!-- if(window==top) { document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> All Classes <noscript></noscript>
SUMMARY:NESTED|FIELD|CONSTR|METHOD
DETAIL:FIELD|CONSTR|METHOD
<!-- ======== END OF BOTTOM NAVBAR ======= -->
Submit a bug or feature Copyright 2003 Sun Microsystems, Inc. All rights reserved.
name
- the name to which the object is bound; cannot be null 对象要绑定的名称,不能为null
value
- the object to be bound 要绑定的对象
IllegalStateException
- if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出
public void putValue(Stringname, Objectvalue)
setAttribute(java.lang.String, java.lang.Object)
从版本2.2以来,该方法被setAttribute(java.lang.String, java.lang.Object)所替代。
name
- the name to which the object is bound; cannot be null 对象要绑定的名称,不能为null
value
- the object to be bound; cannot be null 要绑定的对象,不能为null
IllegalStateException
- if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出
public void removeAttribute(Stringname)
After this method executes, and if the object implements HttpSessionBindingListener
, the container calls HttpSessionBindingListener.valueUnbound
. The container then notifies any HttpSessionAttributeListener
s in the web application. 在方法执行之后,如果对象实现了HttpSessionBindingListener,那么容器调用HttpSessionBindingListener.valueUnbound。 容器通知web应用中的所有HttpSessionAttributeListener。
name
- the name of the object to remove from this session 要从session中删除的对象名称
IllegalStateException
- if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出
public void removeValue(Stringname)
removeAttribute(java.lang.String)
从版本2.2以来,该方法被removeAttribute(java.lang.String)所替代。
name
- the name of the object to remove from this session 要从session中删除的对象名称
IllegalStateException
- if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出
public void invalidate()
IllegalStateException
- if this method is called on an already invalidated session 如果方法调用是基于一个已经无效的会话则抛出
public boolean isNew()
true
if the client does not yet know about the session or if the client chooses not to join the session. For example, if the server used only cookie-based sessions, and the client had disabled the use of cookies, then a session would be new on each request. 如果客户端不知道该会话或者没有选择加入该会话,返回true。比如,如果服务器使用基于cookie的会话, 客户端不能禁用cookies,那么会话对于每一个请求将是新的。
true
if the server has created a session, but the client has not yet joined 如果服务器创建了一个会话,但是客户端还没有加入,返回true
IllegalStateException
- if this method is called on an already invalidated session 如果方法调用是基于一个已经无效的会话则抛出
<!-- -->
|
JavaTM 2 Platform Ent. Ed. v1.4 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES <!-- if(window==top) { document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> All Classes <noscript></noscript> | |||||||
SUMMARY:NESTED|FIELD|CONSTR|METHOD | DETAIL:FIELD|CONSTR|METHOD |
Copyright 2003 Sun Microsystems, Inc. All rights reserved.