Skip to end of metadata
Go to start of metadata

Overview 

The SessionMap is an extended version of a Map with a sessionID property.  The sessionID property is a unique identifier for a SessionMap.  Attributes are added to the SessionMap using standard Map operations.

Examples of the SessionMap in use may be found in the authoring sections of the chat and noticeboard tools. 

When should a SessionMap be Used

Attributes should be stored in the request scope whenever possible.  If this is not practical, then they may be stored in the session scope if it is certain that only one instance of the module will be used at a time.   For all other cases attributes should be stored in a SessionMap object.

Examples of where the SessionMap object could be used.

  • In learning pages it is possible for two instances of the tool to be running at the same time. If it is necessary to use session variables (ie it just can't be done using the request) then use the SessionMap.
  • Normally the authoring pages use the session as it is very difficult to do the attachment lists without using the session. To avoid potential conflicts (e.g. Monitoring pages may reuse Authoring pages to implement define later) the authoring screens should reuse the session.

How to use a SessionMap

Calling the default constructor will create a SessionMap object with a unique sessionID value.  The unique sessionID can then by used to store the SessionMap object in the HttpSession.

To retreive the SessionMap from the HttpSession each client request must include the sessionID as a parameter.

The sessionID can be made available to a page by setting it as a request attribute or placing it with in a struts form.  The following example uses a struts form.

To access a SessionMap object within a jsp page use the following.

If the sessionMapID is stored within a struts form (in request scope) then use the following.

Retrieving elements from the SessionMap is the same for any other Map.

It is important to remove the SessionMap object from the HttpSession when it is no longer needed.  For the authoring pages, the AuthoringButton tag has an attribute customiseSessionID that passes the sessionID to the ClearSessionAction class. So the method in ClearSessionAction will typically be:

Finding out what is in the session

It can sometimes be hard to work out what is in the session. Putting this code in your JSP will show the current session and request scoped objects

<p>Session Scope</p>
<p>
  <c:forEach var="obj" items="${sessionScope}">
    <c:out value="${obj}"/><BR/>
  </c:forEach>
</p>
<p>Request Scope</p>
<p>
  <c:forEach var="obj" items="${requestScope}">
    <c:out value="${obj}"/><BR/>
  </c:forEach>
</p>
  • No labels