com.evanmclean.evlib.servlet
Class ServletUtils

java.lang.Object
  extended by com.evanmclean.evlib.servlet.ServletUtils

public final class ServletUtils
extends Object

Various utility functions for servlets.

Author:
Evan McLean McLean Computer Services (see the overview for copyright and licensing.)

Method Summary
static int getIntParameter(ServletRequest req, String name, int def)
          Get the parameter from the request, trimming it and coverting to an integer.
static String getParameter(ServletRequest req, String name)
          Get the parameter from the request, trimming it and returning an empty string if it doesn't exist.
static String getParameter(ServletRequest req, String name, String def)
          Get the parameter from the request, trimming it, and if blank then return the specified default value.
static File getTempDir(GenericServlet servlet)
          Get the directory where the servlet can put temporary files.
static File getTempDir(Servlet servlet)
          Get the directory where the servlet can put temporary files.
static File getTempDir(ServletConfig servlet_config)
          Get the directory where the servlet can put temporary files.
static File getTempDir(ServletContext servlet_context)
          Get the directory where the servlet can put temporary files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getIntParameter

public static int getIntParameter(ServletRequest req,
                                  String name,
                                  int def)
Get the parameter from the request, trimming it and coverting to an integer. If the parameter is not specified or is not a valid number, then a specified default value is returned.

Parameters:
req - The request object.
name - The name of the parameter.
def - The default value to return if the parameter is not a valid number.
Returns:
Returns the parameter as an integer, or the defautl vaule.

getParameter

public static String getParameter(ServletRequest req,
                                  String name)
Get the parameter from the request, trimming it and returning an empty string if it doesn't exist.

Parameters:
req - The request object.
name - The name of the parameter.
Returns:
Returns the trimmed parameter, or an empty string.

getParameter

public static String getParameter(ServletRequest req,
                                  String name,
                                  String def)
Get the parameter from the request, trimming it, and if blank then return the specified default value.

Parameters:
req - The request object.
name - The name of the parameter.
def - The default to return if the parameter is blank.
Returns:
Returns the trimmed parameter, or the default value.

getTempDir

public static File getTempDir(GenericServlet servlet)
                       throws ServletException
Get the directory where the servlet can put temporary files.

Parameters:
servlet -
Returns:
Returns the directory for temporary files.
Throws:
ServletException - An error occurred getting the temporary directory.

getTempDir

public static File getTempDir(Servlet servlet)
                       throws ServletException
Get the directory where the servlet can put temporary files.

Parameters:
servlet -
Returns:
Returns the directory for temporary files.
Throws:
ServletException - An error occurred getting the temporary directory.

getTempDir

public static File getTempDir(ServletConfig servlet_config)
                       throws ServletException
Get the directory where the servlet can put temporary files.

Parameters:
servlet_config -
Returns:
Returns the directory for temporary files.
Throws:
ServletException - An error occurred getting the temporary directory.

getTempDir

public static File getTempDir(ServletContext servlet_context)
                       throws ServletException
Get the directory where the servlet can put temporary files.

Parameters:
servlet_context -
Returns:
Returns the directory for temporary files.
Throws:
ServletException - An error occurred getting the temporary directory.