com.zeevbelkin.commons
Class ServletUtils

java.lang.Object
  extended by com.zeevbelkin.commons.ServletUtils

public class ServletUtils
extends java.lang.Object

this class contains utilities those help to wrire servlets and JSP's

Author:
Zeev (Vladimir) Belkin

Constructor Summary
ServletUtils()
           
 
Method Summary
static java.lang.String getContextRoot(javax.servlet.http.HttpServletRequest request)
          returns an absolute URL of the running web-application
static javax.servlet.http.Cookie getCookie(java.lang.String name, javax.servlet.http.HttpServletRequest request)
          obtains the cookie by the name
static java.lang.String getCookieValue(java.lang.String name, javax.servlet.http.HttpServletRequest request)
          obtains the cookie value by the name
static java.lang.String getParameterWithReferer(java.lang.String name, javax.servlet.http.HttpServletRequest request)
          This method tries to extract a parameter from the request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletUtils

public ServletUtils()
Method Detail

getContextRoot

public static java.lang.String getContextRoot(javax.servlet.http.HttpServletRequest request)
returns an absolute URL of the running web-application

Returns:
the absolute context URL

getCookie

public static javax.servlet.http.Cookie getCookie(java.lang.String name,
                                                  javax.servlet.http.HttpServletRequest request)
obtains the cookie by the name

Parameters:
name - the cookie name
Returns:
cookie with the given name

getCookieValue

public static java.lang.String getCookieValue(java.lang.String name,
                                              javax.servlet.http.HttpServletRequest request)
obtains the cookie value by the name

Parameters:
name - the cookie name
Returns:
the cookie value

getParameterWithReferer

public static java.lang.String getParameterWithReferer(java.lang.String name,
                                                       javax.servlet.http.HttpServletRequest request)
This method tries to extract a parameter from the request. In case if the parameter is not available in the request body or URL, the method tries to get the parameter value from the referer URL (if any).

Parameters:
name - the parameter name
Returns:
The parameter value if it presents of null in case of failure.