org.chwf.servlet
Class ServletData

java.lang.Object
  |
  +--org.chwf.registry.UserRegistry
        |
        +--org.chwf.servlet.ServletData
All Implemented Interfaces:
java.io.Serializable

public class ServletData
extends UserRegistry

Utility class that acts as a mechanism to pass the servlet context, request and session to lower level methods without passing them explicitly as parameters. The data is stored in a ThreadLocal variable, allowing it to be retrieved via static methods.

Author:
Paul Strack
See Also:
Serialized Form

Constructor Summary
ServletData()
           
 
Method Summary
static void forward(java.lang.String page)
          Forward to specified page.
static void forwardError(java.lang.String errorPage, java.lang.Throwable error)
          Cache the error and forward to the error page.
static javax.servlet.ServletContext getApplication()
          Return the ServletContext (application in JSP terms).
static javax.servlet.http.HttpServletRequest getRequest()
          Return the request.
static javax.servlet.http.HttpServletResponse getResponse()
          Return the response.
static javax.servlet.http.HttpSession getSession()
          Return the session.
static void init(javax.servlet.ServletContext application, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Initialize the servlet registry with servlet data.
static void redirectError(java.lang.String errorPage, java.lang.Throwable error)
          Cache the error and redirect to the error page.
static void release()
          Releases servlet data.
static void retrieveErrorDataFromSession()
          Retrieve error data from the session and cache it in the request.
 
Methods inherited from class org.chwf.registry.UserRegistry
getRegistry, getRegistryEntry, getSingleton, getSingleton, initGlobalRegistry, initLocalRegistry, isInitialized, overwriteRegistryEntry, releaseGlobalRegistry, releaseLocalRegistry, releaseSingleton, removeRegistryEntry, setRegistryEntry
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletData

public ServletData()
Method Detail

getApplication

public static javax.servlet.ServletContext getApplication()
Return the ServletContext (application in JSP terms).

Returns:
The servlet context.

getSession

public static javax.servlet.http.HttpSession getSession()
Return the session.

Returns:
The session.

getRequest

public static javax.servlet.http.HttpServletRequest getRequest()
Return the request.

Returns:
The request.

getResponse

public static javax.servlet.http.HttpServletResponse getResponse()
Return the response.

Returns:
The response.

forward

public static void forward(java.lang.String page)
                    throws javax.servlet.ServletException,
                           java.io.IOException
Forward to specified page.

Parameters:
page - The target page.
Throws:
javax.servlet.ServletException - For servlet exceptions.
java.io.IOException - For IO exceptions.

forwardError

public static void forwardError(java.lang.String errorPage,
                                java.lang.Throwable error)
                         throws javax.servlet.ServletException,
                                java.io.IOException
Cache the error and forward to the error page.

Parameters:
errorPage - The target page.
error - The error.
Throws:
javax.servlet.ServletException - For servlet exceptions.
java.io.IOException - For IO exceptions.

redirectError

public static void redirectError(java.lang.String errorPage,
                                 java.lang.Throwable error)
                          throws java.io.IOException
Cache the error and redirect to the error page.

Parameters:
errorPage - The target page.
error - The error.
Throws:
java.io.IOException - For IO exceptions.

retrieveErrorDataFromSession

public static void retrieveErrorDataFromSession()
Retrieve error data from the session and cache it in the request.


init

public static void init(javax.servlet.ServletContext application,
                        javax.servlet.http.HttpServletRequest request,
                        javax.servlet.http.HttpServletResponse response)
Initialize the servlet registry with servlet data. This is a system method and should not be used by developers except in testing.

Parameters:
application - The servlet context.
request - The request.
response - The response.

release

public static void release()
Releases servlet data. This is a system method and should not be used by developers except in testing.



Copyright © 2002-2004, Paul Strack. All Rights Reserved.