jodd.servlet
Class ServletUtil

java.lang.Object
  extended by jodd.servlet.ServletUtil

public class ServletUtil
extends java.lang.Object

Miscellaneous servlet utilities.


Field Summary
static java.lang.String VALID_SCHEME_CHARS
          Valid characters in a scheme, as specified by RFC 1738.
 
Constructor Summary
ServletUtil()
           
 
Method Summary
static java.lang.String debug(javax.servlet.http.HttpServletRequest request)
          Returns a string with debug info from all servlet objects.
static java.lang.String debug(javax.servlet.http.HttpServletRequest request, javax.servlet.jsp.PageContext page)
          Returns a string with debug info from all servlet objects, including pageScope.
static java.lang.Object getAttributeValue(javax.servlet.http.HttpServletRequest request, java.lang.String name)
           
static java.lang.Object getAttributeValue(javax.servlet.http.HttpServletRequest request, java.lang.String name, javax.servlet.jsp.PageContext page)
          Returns non-null attribute value.
static java.lang.String getAuthPassword(javax.servlet.http.HttpServletRequest request)
          Decodes the "Authorization" header and retrieves the password from it.
static java.lang.String getAuthUsername(javax.servlet.http.HttpServletRequest request)
          Decodes the "Authorization" header and retrieves the user's name from it.
static javax.servlet.http.Cookie getCookie(javax.servlet.http.HttpServletRequest request, java.lang.String cookieName)
          Returns cookie value from client.
static java.util.Map getRequestAttributes(javax.servlet.ServletRequest request)
          Returns a new map containing request attributes.
static java.lang.Object getRequestParameter(javax.servlet.ServletRequest request, java.lang.String name)
          Return HTTP request parameter as String or String[].
static java.util.Map getRequestParameters(javax.servlet.ServletRequest request)
          Returns a new map containing request parameters.
static java.util.Map getSessionAttributes(javax.servlet.http.HttpSession session)
           
static java.lang.Object getValue(javax.servlet.http.HttpServletRequest request, java.lang.String name)
           
static java.lang.Object getValue(javax.servlet.http.HttpServletRequest request, java.lang.String name, javax.servlet.jsp.PageContext page)
          Returns non-null value of property/attribute.
static boolean isAbsoluteUrl(java.lang.String url)
          Returns true if current URL is absolute, false otherwise.
static boolean isMultipartRequest(javax.servlet.http.HttpServletRequest request)
          Returns true if a request is multi-part request.
static void loadRequestAttributes(java.util.Map map, javax.servlet.ServletRequest request)
           
static void loadRequestParameters(java.util.Map map, javax.servlet.ServletRequest request)
           
static void loadSessionAttributes(java.util.Map destination, javax.servlet.http.HttpSession session)
          Loads session attributes into a map.
static void requireAuthentication(javax.servlet.http.HttpServletResponse resp, java.lang.String realm)
          Sends correct headers to require basic authentication for the given realm.
static java.lang.String resolveUrl(java.lang.String url, javax.servlet.http.HttpServletRequest request)
           
static java.lang.String resolveUrl(java.lang.String url, javax.servlet.jsp.PageContext pageContext)
           
static java.lang.String resolveUrl(java.lang.String url, java.lang.String context)
           
static void setBrowserVary(javax.servlet.http.HttpServletResponse response)
          Sets the Vary response header to User-Agent to indicate that the page content varies depending on which user agent (browser) is being used.
static void setRequestAttributes(javax.servlet.ServletRequest request, java.util.Map attributes)
          Transfer attributes from a map to request.
static void setSessionAttributes(javax.servlet.http.HttpSession session, java.util.Map attributes)
           
static java.lang.String stripSession(java.lang.String url)
          Strips a servlet session ID from url.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALID_SCHEME_CHARS

public static final java.lang.String VALID_SCHEME_CHARS
Valid characters in a scheme, as specified by RFC 1738.

See Also:
Constant Field Values
Constructor Detail

ServletUtil

public ServletUtil()
Method Detail

isMultipartRequest

public static boolean isMultipartRequest(javax.servlet.http.HttpServletRequest request)
Returns true if a request is multi-part request.


setBrowserVary

public static void setBrowserVary(javax.servlet.http.HttpServletResponse response)
Sets the Vary response header to User-Agent to indicate that the page content varies depending on which user agent (browser) is being used.


getAuthUsername

public static java.lang.String getAuthUsername(javax.servlet.http.HttpServletRequest request)
Decodes the "Authorization" header and retrieves the user's name from it. Returns null if the header is not present.


getAuthPassword

public static java.lang.String getAuthPassword(javax.servlet.http.HttpServletRequest request)
Decodes the "Authorization" header and retrieves the password from it. Returns null if the header is not present.


requireAuthentication

public static void requireAuthentication(javax.servlet.http.HttpServletResponse resp,
                                         java.lang.String realm)
                                  throws java.io.IOException
Sends correct headers to require basic authentication for the given realm.

Throws:
java.io.IOException

getCookie

public static javax.servlet.http.Cookie getCookie(javax.servlet.http.HttpServletRequest request,
                                                  java.lang.String cookieName)
Returns cookie value from client.

Returns:
cookie value or null if cookie with specified name doesn't exist.

getRequestParameter

public static java.lang.Object getRequestParameter(javax.servlet.ServletRequest request,
                                                   java.lang.String name)
Return HTTP request parameter as String or String[].


setRequestAttributes

public static void setRequestAttributes(javax.servlet.ServletRequest request,
                                        java.util.Map attributes)
Transfer attributes from a map to request.


getRequestAttributes

public static java.util.Map getRequestAttributes(javax.servlet.ServletRequest request)
Returns a new map containing request attributes.


loadRequestAttributes

public static void loadRequestAttributes(java.util.Map map,
                                         javax.servlet.ServletRequest request)

getRequestParameters

public static java.util.Map getRequestParameters(javax.servlet.ServletRequest request)
Returns a new map containing request parameters. Request parameter may be either String or String[].

See Also:
getRequestParameter(ServletRequest, String)

loadRequestParameters

public static void loadRequestParameters(java.util.Map map,
                                         javax.servlet.ServletRequest request)

loadSessionAttributes

public static void loadSessionAttributes(java.util.Map destination,
                                         javax.servlet.http.HttpSession session)
Loads session attributes into a map.


getSessionAttributes

public static java.util.Map getSessionAttributes(javax.servlet.http.HttpSession session)

setSessionAttributes

public static void setSessionAttributes(javax.servlet.http.HttpSession session,
                                        java.util.Map attributes)

getAttributeValue

public static java.lang.Object getAttributeValue(javax.servlet.http.HttpServletRequest request,
                                                 java.lang.String name,
                                                 javax.servlet.jsp.PageContext page)
Returns non-null attribute value. All scopes are examined in the following order: page (if exist), request, session, application.


getAttributeValue

public static java.lang.Object getAttributeValue(javax.servlet.http.HttpServletRequest request,
                                                 java.lang.String name)

getValue

public static java.lang.Object getValue(javax.servlet.http.HttpServletRequest request,
                                        java.lang.String name,
                                        javax.servlet.jsp.PageContext page)
Returns non-null value of property/attribute. Scopes are examined in the following order: page (if exist), request, request parameters, session, application.


getValue

public static java.lang.Object getValue(javax.servlet.http.HttpServletRequest request,
                                        java.lang.String name)

isAbsoluteUrl

public static boolean isAbsoluteUrl(java.lang.String url)
Returns true if current URL is absolute, false otherwise.


stripSession

public static java.lang.String stripSession(java.lang.String url)
Strips a servlet session ID from url. The session ID is encoded as a URL "path parameter" beginning with "jsessionid=". We thus remove anything we find between ";jsessionid=" (inclusive) and either EOS or a subsequent ';' (exclusive).


resolveUrl

public static java.lang.String resolveUrl(java.lang.String url,
                                          javax.servlet.jsp.PageContext pageContext)

resolveUrl

public static java.lang.String resolveUrl(java.lang.String url,
                                          javax.servlet.http.HttpServletRequest request)

resolveUrl

public static java.lang.String resolveUrl(java.lang.String url,
                                          java.lang.String context)

debug

public static java.lang.String debug(javax.servlet.http.HttpServletRequest request)
Returns a string with debug info from all servlet objects.

See Also:
debug(javax.servlet.http.HttpServletRequest, javax.servlet.jsp.PageContext)

debug

public static java.lang.String debug(javax.servlet.http.HttpServletRequest request,
                                     javax.servlet.jsp.PageContext page)
Returns a string with debug info from all servlet objects, including pageScope.



Copyright ©2008 Jodd Team