Class ServletRequest

All Implemented Interfaces:
DispatchRequest, Request

public class ServletRequest extends AbstractClientRequest
Servlet-based implementation of the TilesApplicationContext interface.
  • Constructor Details

    • ServletRequest

      public ServletRequest(ApplicationContext applicationContext, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      Creates a new instance of ServletTilesRequestContext.
      Parameters:
      applicationContext - The application context.
      request - The request object.
      response - The response object.
  • Method Details

    • getHeader

      public Map<String,String> getHeader()
      Return an immutable Map that maps header names to the first (or only) header value (as a String).
      Returns:
      The header map.
    • getResponseHeaders

      public Addable<String> getResponseHeaders()
      Return an Addable object that can be used to write headers to the response.
      Returns:
      An Addable object.
    • getHeaderValues

      public Map<String,String[]> getHeaderValues()
      Return an immutable Map that maps header names to the set of all values specified in the request (as a String array). Header names must be matched in a case-insensitive manner.
      Returns:
      The header values map.
    • getParam

      public Map<String,String> getParam()
      Return an immutable Map that maps request parameter names to the first (or only) value (as a String).
      Returns:
      The parameter map.
    • getParamValues

      public Map<String,String[]> getParamValues()
      Return an immutable Map that maps request parameter names to the set of all values (as a String array).
      Returns:
      The parameter values map.
    • getContext

      public Map<String,Object> getContext(String scope)
      Description copied from interface: Request
      Returns a context map, given the scope name. This method always return a map for all the scope names returned by getAvailableScopes(). That map may be writable, or immutable, depending on the implementation.
      Parameters:
      scope - The name of the scope.
      Returns:
      The context.
    • getRequestScope

      public Map<String,Object> getRequestScope()
    • getSessionScope

      public Map<String,Object> getSessionScope()
    • getAvailableScopes

      public List<String> getAvailableScopes()
      Description copied from interface: Request
      Returns all available scopes. The scopes are ordered according to their lifetime, the innermost, shorter lived scope appears first, and the outermost, longer lived scope appears last. Besides, the scopes "request" and "application" always included in the list.
      Returns:
      All the available scopes.
    • doForward

      public void doForward(String path) throws IOException
      Forwards to a path.
      Specified by:
      doForward in class AbstractClientRequest
      Parameters:
      path - The path to forward to.
      Throws:
      IOException - If something goes wrong when forwarding.
    • doInclude

      public void doInclude(String path) throws IOException
      Includes the result of a path.
      Specified by:
      doInclude in class AbstractClientRequest
      Parameters:
      path - The path to forward to.
      Throws:
      IOException - If something goes wrong when forwarding.
    • getOutputStream

      public OutputStream getOutputStream() throws IOException
      Returns an output stream to be used to write directly in the response.
      Returns:
      The output stream that writes in the response.
      Throws:
      IOException - If something goes wrong when getting the output stream.
    • getWriter

      public Writer getWriter() throws IOException
      Returns a writer to be used to write directly in the response.
      Returns:
      The writer that writes in the response.
      Throws:
      IOException - If something goes wrong when getting the writer.
    • getPrintWriter

      public PrintWriter getPrintWriter() throws IOException
      Returns a print writer to be used to write directly in the response.
      Returns:
      The print writer that writes in the response.
      Throws:
      IOException - If something goes wrong when getting the print writer.
    • isResponseCommitted

      public boolean isResponseCommitted()
      Checks if the response has been committed.
      Returns:
      true only if the response has been committed.
    • setContentType

      public void setContentType(String contentType)
      Sets the content type when rendering the result.
      Parameters:
      contentType - The content type. It should follow the specifications from W3C about content types.
    • getRequestLocale

      public Locale getRequestLocale()
      Return the preferred Locale in which the client will accept content.
      Returns:
      The current request locale. It is the locale of the request object itself, and it is NOT the locale that the user wants to use. See LocaleResolver to implement strategies to resolve locales.
    • getRequest

      public jakarta.servlet.http.HttpServletRequest getRequest()
    • getResponse

      public jakarta.servlet.http.HttpServletResponse getResponse()
    • isUserInRole

      public boolean isUserInRole(String role)
      Determine whether the specified user is in the given role.
      Parameters:
      role - the role to check against.
      Returns:
      true if the user is in the given role.