Servlet--httpsession interface, Httpsessioncontext interface, Cookie class

Source: Internet
Author: User
Tags session id rfc

    • HttpSession interface

Definition
public interface HttpSession

This interface is used by the Servlet engine to implement the correlation between HTTP client and HTTP session. This association may persist for a given amount of time in a multi-outer connection and request. Session is used to maintain state and identify users by crossing multiple request pages under a stateless HTTP protocol. A session can be maintained by a cookie or by rewriting the URL.


Method
1, GetCreationTime
Public long getcreationtime ();
Returns the time the session was established, expressed as the number of milliseconds since 1970-1-1 (GMT).
2, GetId
Public String getId ();
Returns the identifier assigned to the session. An identifier for an HTTP session is a unique string that is created and maintained by the server.
3, Getlastaccessedtime
Public long getlastaccessedtime ();
Returns the time at which the client last issued a request related to this session, if the session was newly established, returning-1. This time is expressed as the number of milliseconds since 1970-1-1 (GMT).
4, Getmaxinactiveinterval
public int getmaxinactiveinterval ();
Returns the number of seconds, which indicates the maximum time that the session is maintained by the Servlet engine when the client does not make a request. After this time, the servlet engine may be terminated by the servlet engine. If this session is not finally
Stop, this method returns-1. Calling this method when the session is invalid will throw a illegalstateexception.
5, GetValue
Public Object GetValue (String name);
Returns an object that is bound to the session with the given name. If no such binding exists, a null value is returned. Calling this method when the session is invalid will throw a illegalstateexception.
6, GetValueNames
Public string[] GetValueNames ();
Returns the name of all data bound to the session in an array. Calling this method when the session is invalid will throw a illegalstateexception.
7, invalidate
public void invalidate ();
This method terminates the session. All data bound to this session will be erased. And the Valueunbound method of the Httpsessionbindinglistener interface is used to issue the notification.
8, IsNew
public boolean isnew ();
Returns a Boolean value to determine if the session is new. If a session has been established by the server but has not received the corresponding client request, this session will be considered new. This means that the client
has not joined the session or is not recognized by the session. It is not possible to return the appropriate session authentication information when he makes the next request. Calling this method when the session is invalid will throw a illegalstateexception.
9, Putvalue
public void Putvalue (String name, Object value);
Binds the given object to the session with the given name. A binding with the same name already exists will be reset. The Valuebound method of the Httpsessionbindinglistener interface is called. Calling this method when the session is invalid will throw a illegalstateexception.
10, RemoveValue
public void RemoveValue (String name);
Cancels the binding of the object of the given name on the session. If the bound object of the given name is not found, this method does nothing. The Valueunbound method of the Httpsessionbindinglistener interface is called. Calling this method when the session is invalid will throw a illegalstateexception.
11, Setmaxinactiveinterval
public int setmaxinactiveinterval (int interval);
Sets a number of seconds, which indicates the maximum time that the session is maintained by the Servlet engine when the client does not make a request. The following method will be canceled \
12, Getsessioncontext
public Httpsessioncontextgetsessioncontext ();

Returns the environment variables in which the session is maintained. This method is the same as all other Httpsessioncontext methods have been canceled.


    • Httpsessioncontext interface
Defined
This interface will be canceled
public interface Httpsessioncontext
This object is a single entity associated with a set of HTTP sessions.
This interface is canceled for security reasons, and it appears in the current version only for compatibility reasons. The method of this interface returns the corresponding value by simulating the definition of the previous version.
Method
1, GetSession
Public HttpSession getsession (String sessionId);
Originally used to return the session associated with the session ID. Now returns a null value.
2, GetIDs
Public enumeration getids ();
It was used to return a list of all session IDs in this environment. Now return to the empty list.
Cookie class
Defined
public class Cookie implements Cloneable
This class describes a cookie, the definition of which you can refer to Netscape Communications
The description of the Corporation can also be referred to RFC 2109.
constructor function
Public Cookie (string name, string value);
Define a cookie with a name-value pair. This name must be accepted by the http/1.1. Name starting with the character $ is reserved by RFC 2109. Given name if it cannot be accepted by http/1.1, the method throws a illegalargumentexception.
Method
1, Getcomment
Public String getcomment ();
Returns a description that describes the purpose of this cookie, and returns a null value if the description is not defined.
2, GetDomain
Public String GetDomain ();
Returns the area where this cookie can occur, and returns a null value if no region is defined.
3, Getmaxage
public int getmaxage ();
This method returns the longest surviving period specified by this cookie. If the longest surviving period is not defined, the party
The law returns-1.
4, GetName
Public String getName ();
The method returns the cookie name.
5, GetPath
Public String GetPath ();
Returns the prefix of all URL paths valid for this cookie, or null if undefined.
6, Getsecure
public boolean getsecure ();
If this cookie is only transmitted through the secure channel, it returns True, otherwise false.
7, GetValue
Public String getValue ();
The method returns the value of the cookie.
8, GetVersion
public int getversion ();
Returns the version of the cookie. Version 1 is interpreted by RFC 2109. Version 0 is explained by the instructions of the Netscape communicationscorporation. The newly constructed cookie uses version 0 by default.
9, Setcomment
public void Setcomment (String purpose);
If a user submits this cookie to another user, the purpose of the cookie must be described through this description. This property is not supported in version 0.
10, SetDomain
public void SetDomain (String pattern);
This method sets the properties of the valid domain for the cookie. This property specifies the area where the cookie can occur. A valid field begins with a point (. foo.com), which means that the cookie is visible to hosts in the specified domain name resolution system (possibly www.foo.com but not a.b.foo.com). By default, a cookie can only return the host on which it was saved.
11, Setmaxage
public void Setmaxage (int expiry);
This method sets the maximum survival time for this cookie. After this period of survival, the cookie will be final. A negative number indicates that the cookie will not take effect and 0 will delete the cookie from the client.
12, SetPath
public void SetPath (String uri);
This method sets the path property of the cookie. The client can only return a cookie to a path that begins with a String of this given path.
13, SetSecure
public void SetSecure (Boolean flag);
Indicates that this cookie can only be sent over a secure channel (such as HTTPS). This setting is only possible if the server that generated the cookie uses the security protocol to send this cookie value.
14, SetValue
public void SetValue (String newvalue);
Set the value of this cookie to use BASE64 encoding for binary data. Version 0 cannot use spaces, {}, (), =,,,,,/、?、 @,:, and;.
15, Setversion
public void setversion (int v);
Set the version number of the cookie


    • Httpsessionbindingevent class
Defined
public class Httpsessionbindingeventextends EventObject
This event is connected Httpsessionbindinglistener when the HttpSession is heard to bind and unbind. This may be a result of a session being terminated or invalidated. The event source is Httpsession.putvalue or httpsession.removevalue.
constructor function
Public Httpsessionbindingevent (HttpSession session, String name);
Constructs a new httpsessionbindingevent by the Session that caused the event and the name of the object in which the binding or unbind occurred.
Method
1, GetName
Public String getName ();
Returns the name of the object on which the binding and unbind occurred.
2, GetSession
Public HttpSession getsession ();
Returns the name of the session where the binding and unbind occurred.

Servlet--httpsession interface, Httpsessioncontext interface, Cookie class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.