com.jfw.web.util
Class SessionUtils

java.lang.Object
  extended by com.jfw.web.util.SessionUtils

public final class SessionUtils
extends java.lang.Object

Implements methods for manage a session. All methods are static and thread safe.


Constructor Summary
SessionUtils()
           
 
Method Summary
static javax.servlet.http.HttpSession create(javax.servlet.http.HttpServletRequest request)
          Create a session.
static javax.servlet.http.HttpSession get(javax.servlet.http.HttpServletRequest request)
          Get the session.
static javax.servlet.http.HttpSession get(javax.servlet.http.HttpServletRequest request, boolean create)
          Get the session.
static java.lang.Object getAttribute(javax.servlet.http.HttpServletRequest request, java.lang.String key)
          Get an attribute from session.
static java.lang.Object getAttribute(javax.servlet.http.HttpServletRequest request, java.lang.String key, java.lang.Object defaultValue)
          Get an attribute from session.
static java.lang.Object getAttribute(javax.servlet.http.HttpSession session, java.lang.String key)
          Get an attribute from session.
static java.lang.Object getAttribute(javax.servlet.http.HttpSession session, java.lang.String key, java.lang.Object defaultValue)
          Get an attribute from session.
static boolean setAttribute(javax.servlet.http.HttpServletRequest request, boolean create, java.lang.String key, java.lang.Object value)
          Add and attribute in session.
static boolean setAttribute(javax.servlet.http.HttpServletRequest request, java.lang.String key, java.lang.Object value)
          Add and attribute in session.
static boolean setAttribute(javax.servlet.http.HttpSession session, java.lang.String key, java.lang.Object value)
          Add and attribute in session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionUtils

public SessionUtils()
Method Detail

create

public static javax.servlet.http.HttpSession create(javax.servlet.http.HttpServletRequest request)
Create a session.

Parameters:
request - an HttpServletRequest object.
Returns:
an HttpSession object.

get

public static javax.servlet.http.HttpSession get(javax.servlet.http.HttpServletRequest request,
                                                 boolean create)
Get the session.

Parameters:
request - an HttpServletRequest object.
create - if true create the session if not exist, if false the session will not created.
Returns:
an HttpSession object.

get

public static javax.servlet.http.HttpSession get(javax.servlet.http.HttpServletRequest request)
Get the session. If session not exist will created.

Parameters:
request - an HttpServletRequest object.
Returns:
an HttpSession object.

getAttribute

public static java.lang.Object getAttribute(javax.servlet.http.HttpServletRequest request,
                                            java.lang.String key)
Get an attribute from session.

Parameters:
request - an HttpServletRequest object.
key - the name of the attribute.
Returns:
the attribute value or null if the attribute not exist or if the session not exist.

getAttribute

public static java.lang.Object getAttribute(javax.servlet.http.HttpServletRequest request,
                                            java.lang.String key,
                                            java.lang.Object defaultValue)
Get an attribute from session.

Parameters:
request - an HttpServletRequest object.
key - the name of the attribute.
defaultValue - the default value.
Returns:
the attribute value or the default value if the attribute not exist or if the session not exist.

getAttribute

public static java.lang.Object getAttribute(javax.servlet.http.HttpSession session,
                                            java.lang.String key)
Get an attribute from session.

Parameters:
session - an HttpSession object.
key - the name of the attribute.
Returns:
the attribute value or null if the attribute not exist.

getAttribute

public static java.lang.Object getAttribute(javax.servlet.http.HttpSession session,
                                            java.lang.String key,
                                            java.lang.Object defaultValue)
Get an attribute from session.

Parameters:
session - an HttpSession object.
key - the name of the attribute.
defaultValue - the default value.
Returns:
the attribute value or the default value if the attribute not exist.

setAttribute

public static boolean setAttribute(javax.servlet.http.HttpSession session,
                                   java.lang.String key,
                                   java.lang.Object value)
Add and attribute in session.

Parameters:
session - an HttpSession object.
key - the name of the attribute.
value - the valule of the attribute.
Returns:
true if is added, false in other cases.

setAttribute

public static boolean setAttribute(javax.servlet.http.HttpServletRequest request,
                                   boolean create,
                                   java.lang.String key,
                                   java.lang.Object value)
Add and attribute in session.

Parameters:
request - an HttpServletRequest object.
create - if true create the session if not exist, if false the session will not created.
key - the name of the attribute.
value - the valule of the attribute.
Returns:
true if session exist and attribute is added, false in other cases.

setAttribute

public static boolean setAttribute(javax.servlet.http.HttpServletRequest request,
                                   java.lang.String key,
                                   java.lang.Object value)
Add and attribute in session.

Parameters:
request - an HttpServletRequest object.
key - the name of the attribute.
value - the valule of the attribute.
Returns:
true if session exist and attribute is added, false in other cases.