Examples

response is the outgoing HttpServletResponse exposed to every JSSP page and web app. Use it to declare the content type, add headers or cookies, and redirect — everything about the reply except the body itself, which you emit with 📕 write.

Set 📕 setContentType first, before any output.

response.setContentType("application/json"); // set the Content-Type header
response.addHeader("Cache-Control", "no-cache"); // add an HTTP header
response.sendRedirect("https://example.com/login"); // temporary redirect

Methods

Method Description
setContentType(type) Set the Content-Type header of the response
addHeader(key, value) Add an HTTP header
addCookie(cookie) Add a cookie to the response
sendRedirect(url) Temporary (302) redirection to another URL
sendError(code) Return an error response with the given HTTP code

See also

  • 📕 request - The HttpServletRequest object — read query parameters, body, headers and client info in a JSSP.
  • 📕 setContentType - Set the HTTP Content-Type header of a JSSP response.
  • 📕 write - Append a string to the JSSP response body — the server-side equivalent of print.