org.chwf.servlet
Class ServletUtils

java.lang.Object
  |
  +--org.chwf.servlet.ServletUtils

public class ServletUtils
extends java.lang.Object

Class with utility methods for servlets and JSP.

Author:
Paul Strack

Field Summary
static int EVAL_BODY_TAG
          BodyTag.EVAL_BODY_TAG.
static java.lang.String EXCEPTION_CACHE_NAME
          The name used to cache errors.
 
Constructor Summary
ServletUtils()
           
 
Method Summary
static void cacheError(javax.servlet.http.HttpServletRequest request, java.lang.Throwable error)
          Cached an error in the request.
static java.lang.String encode(java.lang.String value)
          Place holder to deal with deprecated java.net.URLEncoder.encode() in JDK 1.4.
static void forward(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.String uri)
          Forward to the indicated URI.
static java.lang.StringBuffer getURLWithQueryString(javax.servlet.http.HttpServletRequest request)
          Get the URL, as per HttpUtils.getRequestURL(), and append the query string.
static void include(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.String uri)
          Include the indicated URI.
static java.lang.Throwable retrieveError(javax.servlet.http.HttpServletRequest request)
          Retrieves a cached error from the request.
static void setPageAttribute(javax.servlet.jsp.PageContext context, java.lang.String key, java.lang.Object value)
          Utility method to compensate for the "feature" of PageContext that it throws a NullPointerException when setting a null attribute value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXCEPTION_CACHE_NAME

public static final java.lang.String EXCEPTION_CACHE_NAME
The name used to cache errors. Identical to PageContext.EXCEPTION.

EVAL_BODY_TAG

public static final int EVAL_BODY_TAG
BodyTag.EVAL_BODY_TAG. Defined to cut down on deprecation warnings.
Constructor Detail

ServletUtils

public ServletUtils()
Method Detail

cacheError

public static void cacheError(javax.servlet.http.HttpServletRequest request,
                              java.lang.Throwable error)
Cached an error in the request.

Parameters:
request - The request.
error - The error.

retrieveError

public static java.lang.Throwable retrieveError(javax.servlet.http.HttpServletRequest request)
Retrieves a cached error from the request.

Parameters:
request - The request.
Returns:
The error.

encode

public static java.lang.String encode(java.lang.String value)
Place holder to deal with deprecated java.net.URLEncoder.encode() in JDK 1.4.

Parameters:
value - The value to encode.
Returns:
The encoded value.

forward

public static void forward(javax.servlet.ServletRequest request,
                           javax.servlet.ServletResponse response,
                           java.lang.String uri)
                    throws javax.servlet.ServletException,
                           java.io.IOException
Forward to the indicated URI.
Parameters:
request - The request.
response - The response.
uri - The target URI.
Throws:
javax.servlet.ServletException - For servlet exceptions, or if the URI is not found
java.io.IOException - For IO exceptions.

include

public static void include(javax.servlet.ServletRequest request,
                           javax.servlet.ServletResponse response,
                           java.lang.String uri)
                    throws javax.servlet.ServletException,
                           java.io.IOException
Include the indicated URI.
Parameters:
request - The request.
response - The response.
uri - The target URI.
Throws:
javax.servlet.ServletException - For servlet exceptions, or if the URI is not found
java.io.IOException - For IO exceptions.

getURLWithQueryString

public static java.lang.StringBuffer getURLWithQueryString(javax.servlet.http.HttpServletRequest request)
Get the URL, as per HttpUtils.getRequestURL(), and append the query string.
Parameters:
request - The request.
Returns:
The absolute request URL with the query string.

setPageAttribute

public static void setPageAttribute(javax.servlet.jsp.PageContext context,
                                    java.lang.String key,
                                    java.lang.Object value)
                             throws java.lang.NullPointerException
Utility method to compensate for the "feature" of PageContext that it throws a NullPointerException when setting a null attribute value. This method call the removeAttribute() method if the value is null. Otherwise it calls setAttribute() as usual. If the key is null, it does nothing.
Parameters:
context - The page context.
key - The key value.
value - The attribute value.
Throws:
java.lang.NullPointerException - If the key is null.


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