JSP Response Object is implicitly available to the developer on Java Server Pages. This object implements javax.servlet.ServletResponse interface. It is useful object in setting response to serve the request. This object has a scope for that specific request.
JSP Response Object Example:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@page import="java.io.PrintWriter"%> <html> <head> <title>JSP Request Object Example</title> </head> <body> <% PrintWriter pw = response.getWriter(); pw.print("Hello Jwalant....This is an example of JSP 'Response' object"); %> </body> </html>
Output on Browser: Hello Jwalant....This is example of JSP 'Response' object
As you can see above, using JSP response object, PrintWriter instance is created. Using this PrintWriter object, String response is set that displayed on the browser when JSP served a request.