mn8 Language Reference | Index | ||
ServletSession |
||
|
||
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.
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.
Version: | 0.1 |
Authors: | Remus Pereni (http://neuro.nolimits.ro) |
Location: | |
Inherits: | Concept |
getAttributes |
Returns: Map |
Returns a map containing the attributes bound to this session.
$session = $request.getSession(true) print "Reloaded: " + $session.getAttributes.getValue("nr") + " times." -- the result is -- Reloaded: 5 times.
getCreationTime |
Returns: Integer |
Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.
$session = $request.getSession(true) print "Created: " + Date.create( $session.getCreationTime ).toTXT -- the result is -- Created: Fri Aug 02 16:59:58 EDT 2002
getId |
Returns: String |
Returns a string containing the unique identifier assigned to this session. The identifier is assigned by the servlet container and is implementation dependent.
$session = $request.getSession(true) print "Session ID: " + $session.getId -- the result is -- Session ID: 2rc0xe95z1
getLastAccessedTime |
Returns: Integer |
Returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT.
Actions that your application takes, such as getting or setting a value associated with the session, do not affect the access time.
$session = $request.getSession(true) print "Last access: " + Date.create( $session.getLastAccessedTime ).toTXT -- the result is -- Last access: Fri Aug 02 17:21:32 EDT 2002
getMaxInactiveInterval |
Returns: Integer |
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.
$session = $request.getSession(true) print "Inactive Interval: " + $session.getMaxInactiveInterval -- the result is -- InactiveInterval: 1800
invalidate |
Returns: |
Invalidates this session and unbinds any attributes bound to it.
$session = $request.getSession(true) $session.invalidate -- the result is -- Invalidate this session.
isNew |
Returns: Logical |
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.
$session = $request.getSession(true) print "Is New: " + $session.isNew -- the result is -- Is New: true
setAttributes (Map $attributes) |
Parameters: | ||
|
Returns: |
Set's a map with attributes to be bind to this session.
$session = $request.getSession(true) print "Reloaded: " + $session.getAttributes.getValue("nr") + " times." $attrs = $session.getAttributes $attrs.remove("nr") $attrs.add("nr", 100) print "Set Reloaded to: 100" $session.setAttributes( $attrs) $session.se -- the result is -- Reloaded: 5 times. Set Reloaded to: 100
setMaxInactiveInterval (Integer $interval) |
Parameters: | ||
|
Returns: |
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.
$session = $request.getSession(true) $session.setMaxInactiveInterval(900) print "Inactive Interval: " + $session.getMaxInactiveInterval -- the result is -- InactiveInterval: 900