Interface Response

All Known Implementing Classes:
HttpResponse

public interface Response
The Response interface represents the HTTP response to be sent back to the client.
  • Field Details

  • Method Details

    • status

      Response status(int n)
      Sets the status code for the response of an HTTP request.
      Parameters:
      n - the HTTP code.
      Returns:
      the current Response object for chaining.
    • cacheControl

      Response cacheControl(int maxAge)
      Sets the max-age attribute of control-cache header.
      Parameters:
      maxAge - the max age in milliseconds.
      Returns:
      the current Response object for chaining.
    • lastModified

      Response lastModified(long last)
      Sets the header last-modified in the HTTP response.
      Parameters:
      last - the date in milliseconds.
      Returns:
      the current Response object for chaining.
    • write

      Response write(String msg)
      Writes a string to the response output stream.
      Parameters:
      msg - the string value to write.
      Returns:
      the current Response object for chaining.
    • out

      PrintWriter out() throws IOException
      Gets the PrintWriter object to write to the response output stream.
      Returns:
      the PrintWriter object.
      Throws:
      IOException - if an I/O error occurs.
    • json

      void json(Object obj)
      Writes an object in JSON format to the response output stream.
      Parameters:
      obj - the object to write.
    • redirect

      void redirect(String url)
      Redirects the request to the specified URL.
      Parameters:
      url - the URL to redirect to.
    • setHeader

      Response setHeader(String key, String value)
      Sets a header for the HTTP response.
      Parameters:
      key - the header name.
      value - the header value.
      Returns:
      the current Response object for chaining.
    • setDateHeader

      Response setDateHeader(String name, long time)
      Sets a date header for the HTTP response.
      Parameters:
      name - the header name.
      time - the time in milliseconds.
      Returns:
      the current Response object for chaining.
    • jsp

      void jsp(String jspPage) throws Exception
      Renders a JSP page to the response output stream.
      Parameters:
      jspPage - the JSP page to render.
      Throws:
      Exception - if an error occurs while rendering the JSP page.
    • sendError

      void sendError(int i, String message)
      Sends an error response to the client using the specified status code and message.
      Parameters:
      i - the HTTP status code.
      message - the error message.