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 Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
Http status code constants.static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptioncacheControl
(int maxAge) Sets the max-age attribute of control-cache header.void
Writes an object in JSON format to the response output stream.void
Renders a JSP page to the response output stream.lastModified
(long last) Sets the header last-modified in the HTTP response.out()
Gets the PrintWriter object to write to the response output stream.void
Redirects the request to the specified URL.void
Sends an error response to the client using the specified status code and message.setDateHeader
(String name, long time) Sets a date header for the HTTP response.Sets a header for the HTTP response.status
(int n) Sets the status code for the response of an HTTP request.Writes a string to the response output stream.
-
Field Details
-
REST_INTERNAL_SERVER_ERROR
static final int REST_INTERNAL_SERVER_ERRORHttp status code constants.- See Also:
-
REST_BAD_REQUEST
static final int REST_BAD_REQUEST- See Also:
-
REST_NOT_FOUND
static final int REST_NOT_FOUND- See Also:
-
REST_NOT_MODIFIED
static final int REST_NOT_MODIFIED- See Also:
-
REST_CREATED
static final int REST_CREATED- See Also:
-
-
Method Details
-
status
Sets the status code for the response of an HTTP request.- Parameters:
n
- the HTTP code.- Returns:
- the current Response object for chaining.
-
cacheControl
Sets the max-age attribute of control-cache header.- Parameters:
maxAge
- the max age in milliseconds.- Returns:
- the current Response object for chaining.
-
lastModified
Sets the header last-modified in the HTTP response.- Parameters:
last
- the date in milliseconds.- Returns:
- the current Response object for chaining.
-
write
Writes a string to the response output stream.- Parameters:
msg
- the string value to write.- Returns:
- the current Response object for chaining.
-
out
Gets the PrintWriter object to write to the response output stream.- Returns:
- the PrintWriter object.
- Throws:
IOException
- if an I/O error occurs.
-
json
Writes an object in JSON format to the response output stream.- Parameters:
obj
- the object to write.
-
redirect
Redirects the request to the specified URL.- Parameters:
url
- the URL to redirect to.
-
setHeader
Sets a header for the HTTP response.- Parameters:
key
- the header name.value
- the header value.- Returns:
- the current Response object for chaining.
-
setDateHeader
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
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
Sends an error response to the client using the specified status code and message.- Parameters:
i
- the HTTP status code.message
- the error message.
-