Order the Book

coreservlets
Class ServletUtilities

java.lang.Object
  |
  +--coreservlets.ServletUtilities

public class ServletUtilities
extends Object

Some simple time savers. Note that most are static methods.

Taken from Core Servlets and JavaServer Pages from Prentice Hall and Sun Microsystems Press, http://www.coreservlets.com/. © 2000 Marty Hall; may be freely used or adapted.


Field Summary
static String DOCTYPE
           
 
Constructor Summary
ServletUtilities()
           
 
Method Summary
static String filter(String input)
          Given a string, this method replaces all occurrences of '<' with '<', all occurrences of '>' with '>', and (to handle cases that occur inside attribute values), all occurrences of double quotes with '"' and all occurrences of '&' with '&'.
static Cookie getCookie(Cookie[] cookies, String cookieName)
          Given an array of cookies and a name, this method tries to find and return the cookie from the array that has the given name.
static String getCookieValue(Cookie[] cookies, String cookieName, String defaultValue)
          Given an array of Cookies, a name, and a default value, this method tries to find the value of the cookie with the given name.
static int getIntParameter(HttpServletRequest request, String paramName, int defaultValue)
          Read a parameter with the specified name, convert it to an int, and return it.
static String headWithTitle(String title)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOCTYPE

public static final String DOCTYPE
Constructor Detail

ServletUtilities

public ServletUtilities()
Method Detail

headWithTitle

public static String headWithTitle(String title)

getIntParameter

public static int getIntParameter(HttpServletRequest request,
                                  String paramName,
                                  int defaultValue)
Read a parameter with the specified name, convert it to an int, and return it. Return the designated default value if the parameter doesn't exist or if it is an illegal integer format.

getCookieValue

public static String getCookieValue(Cookie[] cookies,
                                    String cookieName,
                                    String defaultValue)
Given an array of Cookies, a name, and a default value, this method tries to find the value of the cookie with the given name. If there is no cookie matching the name in the array, then the default value is returned instead.

getCookie

public static Cookie getCookie(Cookie[] cookies,
                               String cookieName)
Given an array of cookies and a name, this method tries to find and return the cookie from the array that has the given name. If there is no cookie matching the name in the array, null is returned.

filter

public static String filter(String input)
Given a string, this method replaces all occurrences of '<' with '<', all occurrences of '>' with '>', and (to handle cases that occur inside attribute values), all occurrences of double quotes with '"' and all occurrences of '&' with '&'. Without such filtering, an arbitrary string could not safely be inserted in a Web page.

Order the Book

Order
CSAJSP @ amazon.com

Return to Top-Level Source Code Archive