com.vaadin.flow.server.
Interface VaadinResponse
All Known Implementing Classes:
A generic response from the server, wrapping a more specific response type, e.g. HttpServletResponse.
Since:
1.0
Author:
Vaadin Ltd
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCookie
(jakarta.servlet.http.Cookie cookie) Adds the specified cookie to the response.
static VaadinResponse
Gets the currently processed Vaadin response.
Returns a
OutputStream
for writing binary data in the response.Gets the vaadin service for the context of this response.
Returns a
PrintWriter
object that can send character text to the client.void
Sends an error response to the client using the specified status code and clears the buffer.
void
setCacheTime
(long milliseconds) Sets cache time in milliseconds, -1 means no cache at all.
void
setContentLength
(int len) Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.
void
setContentType
(String contentType) Sets the content type of this response.
void
setDateHeader
(String name, long timestamp) Properly formats a timestamp as a date header.
void
Sets the value of a generic response header.
default void
Sets all conceivable headers that might prevent a response from being stored in any caches.
void
setStatus
(int statusCode) Sets the (http) status code for the response.
-
Method Details
-
setStatus
void setStatus(int statusCode) Sets the (http) status code for the response. If you want to include an error message along the status code, use
sendError(int, String)
instead.HttpServletResponse.setStatus(int)
Parameters:
statusCode
- the status code to setSee Also:
-
setContentType
Sets the content type of this response. If the content type including a charset is set before
getWriter()
is invoked, the returned PrintWriter will automatically use the defined charset.ServletResponse.setContentType(String)
Parameters:
contentType
- a string specifying the MIME type of the contentSee Also:
-
setHeader
Sets the value of a generic response header. If the header had already been set, the new value overwrites the previous one.
HttpServletResponse.setHeader(String, String)
Parameters:
name
- the name of the headervalue
- the header value.See Also:
-
setDateHeader
Properly formats a timestamp as a date header. If the header had already been set, the new value overwrites the previous one.
HttpServletResponse.setDateHeader(String, long)
Parameters:
name
- the name of the headertimestamp
- the number of milliseconds since epochSee Also:
-
getOutputStream
Returns a
OutputStream
for writing binary data in the response.Either this method or getWriter() may be called to write the response, not both.
getWriter()
ServletResponse.getOutputStream()
Returns:
a
OutputStream
for writing binary dataThrows:
IOException
- if an input or output exception occurredSee Also:
-
getWriter
Returns a
PrintWriter
object that can send character text to the client. The PrintWriter uses the character encoding defined using setContentType.Either this method or getOutputStream() may be called to write the response, not both.
getOutputStream()
ServletResponse.getWriter()
Returns:
a
PrintWriter
for writing character textThrows:
IOException
- if an input or output exception occurredSee Also:
-
setCacheTime
void setCacheTime(long milliseconds) Sets cache time in milliseconds, -1 means no cache at all. All required headers related to caching in the response are set based on the time.
Parameters:
milliseconds
- Cache time in milliseconds -
sendError
Sends an error response to the client using the specified status code and clears the buffer. In some configurations, this can cause a predefined error page to be displayed.
HttpServletResponse.sendError(int, String)
Parameters:
errorCode
- the HTTP status codemessage
- a message to accompany the errorThrows:
IOException
- if an input or output exception occursSee Also:
-
getService
VaadinService getService()Gets the vaadin service for the context of this response.
Returns:
the vaadin service
See Also:
-
addCookie
void addCookie(jakarta.servlet.http.Cookie cookie) Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.
HttpServletResponse.addCookie(Cookie)
Parameters:
cookie
- the Cookie to return to the clientSee Also:
-
setContentLength
void setContentLength(int len) Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.
Parameters:
len
- an integer specifying the length of the content being returned to the client -
setNoCacheHeaders
default void setNoCacheHeaders()Sets all conceivable headers that might prevent a response from being stored in any caches.
-
getCurrent
Gets the currently processed Vaadin response. The current response is automatically defined when the request is started. The current response can not be used in e.g. background threads because of the way server implementations reuse response instances.
Returns:
the current Vaadin response instance if available, otherwise
null
-