javax.servlet.http.HttpSession翻译

来源:互联网 发布:企业云盘软件 编辑:程序博客网 时间:2024/06/07 01:33
 Overview Package  Class Tree Deprecated Index Help JavaTM 2 Platform
Ent. Ed. v1.4
 PREV CLASS   NEXT CLASSFRAMES    NO FRAMES     All Classes SUMMARY: NESTED | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD

javax.servlet.http
Interface HttpSession


public interface HttpSession

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

  • View and manipulate information about a session, such as the session identifier, creation time, and last accessed time 查看和操作session信息,比如session标识符,创建时间和上次访问时间
  • Bind objects to sessions, allowing user information to persist across multiple user connections 将对象与会话绑定,允许用户信息持久地跨越多个用户连接

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),因此存储在上下文中的信息对于另一个应用不能直接可见。

Version:
$Version$
Author:
Various
See Also:
HttpSessionBindingListener, HttpSessionContext

Method Summary ObjectgetAttribute(String name)
          Returns the object bound with the specified name in this session, or null if no object is bound under the name. 返回session中指定名称的绑定对象,如果没有对象被绑定,返回null。
 EnumerationgetAttributeNames()
          Returns an Enumeration of String objects containing the names of all the objects bound to this session. 以String对象的枚举形式返回绑定给该session的所有对象名称。
 longgetCreationTime()
          Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.返回session创建的时间,以1970年1月1日0点为起点。
 StringgetId()
          Returns a string containing the unique identifier assigned to this session. 返回一字符串,表示分配给session的唯一的标识符。
 longgetLastAccessedTime()
          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日以来的毫秒值,标记为容器接收到请求的时间。
 intgetMaxInactiveInterval()
          Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses. 以秒为单位返回最大间隔时间,在客户端访问之间servlet容器将保持会话开启。
 ServletContextgetServletContext()
          Returns the ServletContext to which this session belongs. 返回session属于的ServletContext。
 HttpSessionContextgetSessionContext()
          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的以后版本中将被删除。
 ObjectgetValue(String name)
          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()所替代。
 voidinvalidate()
          Invalidates this session then unbinds any objects bound to it. 使session无效,解除所有对象的绑定。
 booleanisNew()
          Returns true if the client does not yet know about the session or if the client chooses not to join the session. 如果客户端不知道该会话或者没有选择加入该会话,返回true。
 voidputValue(String name, Object value)
          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)所替代。
 voidremoveAttribute(String name)
          Removes the object bound with the specified name from this session. 从session中删除指定名称绑定的对象。
 voidremoveValue(String name)
          Deprecated. As of Version 2.2, this method is replaced by removeAttribute(java.lang.String) 从版本2.2以来,该方法被removeAttribute(java.lang.String)所替代。
 voidsetAttribute(String name, Object value)
          Binds an object to this session, using the name specified. 使用指定名称,向session绑定一个对象。
 voidsetMaxInactiveInterval(int interval)
          Specifies the time, in seconds, between client requests before the servlet container will invalidate this session. 以秒为单位指定servlet容器使会话失效之前客户端请求之间的间隔时间。
 

Method Detail

getCreationTime

public long getCreationTime()
Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT. 返回session创建的时间,以1970年1月1日0点为起点。

Returns:
a long specifying when this session was created, expressed in milliseconds since 1/1/1970 GMT long值,表示上一次该会话创建的时间,即从GMT 1970年1月1日以来的毫秒值
Throws:
IllegalStateException - if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出

getId

public String getId()
Returns a string containing the unique identifier assigned to this session. The identifier is assigned by the servlet container and is implementation dependent. 返回一字符串,表示分配给session的唯一的标识符。

Returns:
a string specifying the identifier assigned to this session 表示分配给session的标识符字符串
Throws:
IllegalStateException - if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出

getLastAccessedTime

public 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日以来的毫秒值,标记为容器接收到请求的时间。

Actions that your application takes, such as getting or setting a value associated with the session, do not affect the access time. 应用程序执行的动作,比如获取或设置会话的相关值,不影响访问时间。

Returns:
a 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日以来的毫秒值
Throws:
IllegalStateException - if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出

getServletContext

public ServletContext getServletContext()
Returns the ServletContext to which this session belongs. 返回session属于的ServletContext。

Returns:
The ServletContext object for the web application web应用的ServletContext对象
Since:
2.3

setMaxInactiveInterval

public void setMaxInactiveInterval(int interval)
Specifies the time, in seconds, between client requests before the servlet container will invalidate this session. A negative time indicates the session should never timeout. 以秒为单位指定servlet容器使会话失效之前客户端请求之间的间隔时间。 负值表示会话永远不会超时。

Parameters:
interval - An integer specifying the number of seconds 整数,表示秒数

getMaxInactiveInterval

public int getMaxInactiveInterval()
Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses. After this interval, the servlet container will invalidate the session. The maximum time interval can be set with the setMaxInactiveInterval method. A negative time indicates the session should never timeout. 以秒为单位返回最大间隔时间,在客户端访问之间servlet容器将保持会话开启。 在间隔之后,servlet容器将使会话失效。最大间隔值可以通过setMaxInactiveInterval方法设置。

Returns:
an integer specifying the number of seconds this session remains open between client requests 一个整数值,表示在客户端访问之间servlet容器保持会话开启的时间。
See Also:
setMaxInactiveInterval(int)

getSessionContext

public 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的以后版本中将被删除。


getAttribute

public Object getAttribute(String name)
Returns the object bound with the specified name in this session, or null if no object is bound under the name. 返回session中指定名称的绑定对象,如果没有对象被绑定,返回null。

Parameters:
name - a string specifying the name of the object 指定对象名称的字符串
Returns:
the object with the specified name 指定名称的对象
Throws:
IllegalStateException - if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出

getValue

public Object getValue(String name)
Deprecated. As of Version 2.2, this method is replaced by getAttribute(java.lang.String). 从版本2.2以来,该方法被getAttribute(java.lang.String)所替代。

Parameters:
name - a string specifying the name of the object 指定对象名称的字符串
Returns:
the object with the specified name 指定名称的对象
Throws:
IllegalStateException - if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出

getAttributeNames

public Enumeration getAttributeNames()
Returns an Enumeration of String objects containing the names of all the objects bound to this session. 以String对象的枚举形式返回绑定给该session的所有对象名称。

Returns:
an Enumeration of String objects specifying the names of all the objects bound to this session String对象的枚举形式,表示绑定给该session的所有对象名称。
Throws:
IllegalStateException - if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出

getValueNames

public String[] getValueNames()
Deprecated. As of Version 2.2, this method is replaced by getAttributeNames() 从版本2.2以来,该方法被getAttributeNames()所替代。

Returns:
an array of String objects specifying the names of all the objects bound to this session 表示会话绑定的所有对象名称的String对象数组
Throws:
IllegalStateException - if this method is called on an invalidated session 如果方法调用是基于一个无效的会话则抛出

setAttribute

public void setAttribute(String name,                         Object value)
Binds an object to this session, using the name specified. If an object of the same name is already bound to the session, the object is replaced. 使用指定名称,向session绑定一个对象。如果一个相同名称的对象已绑定给session,原对象被替代。

After this method executes, and if the new object implements HttpSessionBindingListener, the container calls HttpSessionBindingListener.valueBound. The container then notifies any HttpSessionAttributeListeners 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(String name,                     Object value)
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(String name)
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 HttpSessionAttributeListeners 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(String name)
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 如果方法调用是基于一个已经无效的会话则抛出

Overview Package  Class Tree Deprecated Index Help JavaTM 2 Platform
Ent. Ed. v1.4
 PREV CLASS   NEXT CLASSFRAMES    NO FRAMES     All Classes SUMMARY: NESTED | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD
Submit a bug or feature

Copyright 2003 Sun Microsystems, Inc. All rights reserved.

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(String name,                     Object value)
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(String name)
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 HttpSessionAttributeListeners 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(String name)
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 如果方法调用是基于一个已经无效的会话则抛出

Overview Package  Class Tree Deprecated Index Help JavaTM 2 Platform
Ent. Ed. v1.4
 PREV CLASS   NEXT CLASSFRAMES    NO FRAMES     All Classes SUMMARY: NESTED | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD
Submit a bug or feature

Copyright 2003 Sun Microsystems, Inc. All rights reserved.

原创粉丝点击