Class ServletUtil


  • public class ServletUtil
    extends java.lang.Object
    Contains Servlet-related utilities.
    Since:
    6.0.0
    Version:
    $Revision$ $Date$
    • Constructor Summary

      Constructors 
      Constructor Description
      ServletUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void clearQueryStringParameters​(javax.servlet.http.HttpServletRequest request)
      Removes cached query string parameters (if any).
      static java.lang.String getApplicationRequestedPath​(javax.servlet.http.HttpServletRequest request)
      Returns the requested path, relative to the web application root.
      static java.lang.String getQueryStringParameter​(javax.servlet.http.HttpServletRequest request, java.lang.String parameterName)
      Tries to read a request parameter from its query string.
      static java.lang.Object getSessionMutex​(javax.servlet.http.HttpSession session)
      Return the object to synchronize on for the given session.
      static void sendMovedPermanentlyWithNoCache​(javax.servlet.http.HttpServletResponse response, java.lang.String location)
      Sends a HttpServletResponse.SC_MOVED_PERMANENTLY status with a no-cache header.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ServletUtil

        public ServletUtil()
    • Method Detail

      • getApplicationRequestedPath

        public static java.lang.String getApplicationRequestedPath​(javax.servlet.http.HttpServletRequest request)
        Returns the requested path, relative to the web application root. This path starts with '/'. Does not include the query string.
        Parameters:
        request - the http servlet request.
        Returns:
        the path.
        Since:
        6.0.0
      • getQueryStringParameter

        public static java.lang.String getQueryStringParameter​(javax.servlet.http.HttpServletRequest request,
                                                               java.lang.String parameterName)
        Tries to read a request parameter from its query string. If the parameter has multiple values, any of them may be returned.
        Parameters:
        request - the request.
        parameterName - the parameter name.
        Returns:
        the parameter value, or null if it was not found.
        Since:
        8.0.0
      • clearQueryStringParameters

        public static void clearQueryStringParameters​(javax.servlet.http.HttpServletRequest request)
        Removes cached query string parameters (if any).
        Parameters:
        request - the request
        Since:
        14.0.0
      • sendMovedPermanentlyWithNoCache

        public static void sendMovedPermanentlyWithNoCache​(javax.servlet.http.HttpServletResponse response,
                                                           java.lang.String location)
        Sends a HttpServletResponse.SC_MOVED_PERMANENTLY status with a no-cache header.

        The 301 moved permanently HTTP response is cached by default. This method is a utility to send this type of response with caching disabled.

        Parameters:
        response - the response to send the status.
        location - the location to set in the response.
        Since:
        10.0.0
      • getSessionMutex

        public static java.lang.Object getSessionMutex​(javax.servlet.http.HttpSession session)
        Return the object to synchronize on for the given session.
        Parameters:
        session - the session.
        Returns:
        the mutex object.