response object
TRANSCRIPT
8/8/2019 Response Object
http://slidepdf.com/reader/full/response-object 2/14
The response, response is a process to
responding against it request.
Response Object in JSP is used to send
information, or output from web server to
the user.
Response Object sends output in form of
stream to the browser.
This can be redirecting one file to another
file .
8/8/2019 Response Object
http://slidepdf.com/reader/full/response-object 3/14
Response object tells browser what output
has to use or display on browser, andwhat stream of data contain PDF,
html/text, Word, Excel.
The result or the information of a requestis denoted with this object.
The response object handles the output of
the client.
8/8/2019 Response Object
http://slidepdf.com/reader/full/response-object 4/14
This contrasts with the request object.
The class or the interface name of theresponse object is
http.HttpServletResponse.
The response object is written:
Javax.servlet.http.httpservletresponse.
The response object is generally used by
cookies.
The response object is also used withHTTP Headers.
8/8/2019 Response Object
http://slidepdf.com/reader/full/response-object 5/14
HTTP Response Object Work in
Servlet
Request
Response
Http Client
Session
HttpServlet
doGet() {
Process request from Client
using Request object;
Send response to client via
the Response object;
}
8/8/2019 Response Object
http://slidepdf.com/reader/full/response-object 6/14
Methods
setContentType();
addCookie(Cookie cookie)
addHeader(String name, String value)
containsHeader(String name)
setHeader(String name, String value)
sendRedirect(String)
sendError(int status_code)
8/8/2019 Response Object
http://slidepdf.com/reader/full/response-object 7/14
setContentType()
setContentType() method of response object is used to
set the MIME type and character encoding for the page.
General syntax of setContentType() of response object
is as follows:
response.setContentType();
8/8/2019 Response Object
http://slidepdf.com/reader/full/response-object 8/14
For example:
response.setContentType("text/html");
The above statement is used to set the
content type as text/html dynamically.
8/8/2019 Response Object
http://slidepdf.com/reader/full/response-object 9/14
addCookie(Cookie cookie)
addCookie() method of response object isused to add the specified cookie to theresponse.
The addcookie() method is used to write acookie to the response.
If the user wants to add more than one
cookie, then using this method by calling itas many times as the user wants will addcookies.
8/8/2019 Response Object
http://slidepdf.com/reader/full/response-object 10/14
General syntax of addCookie() of
response object is as follows:
response.addCookie(Cookie cookie)
For example:
response.addCookie(Cookie exforsys);
The above statement adds the specified
cookie exforsys to the response.
8/8/2019 Response Object
http://slidepdf.com/reader/full/response-object 11/14
addHeader(String name, String value)
Adds response header with given name andvalue
If the header is already present, then value isadded to the existing header values.
General syntax of addHeader() of responseobject is as follows:
response.addHeader(String name, String
value)
Here the value of string is given as secondparameter and this gets assigned to the header given in first parameter as string name.
8/8/2019 Response Object
http://slidepdf.com/reader/full/response-object 12/14
For example:
response.addHeader(" Author", Exforsys");
The output of above statement is as below:
Author: Exforsys
8/8/2019 Response Object
http://slidepdf.com/reader/full/response-object 13/14
sendRedirect(String)
Sends a redirect response to client with redirect
specified URL location. Contain Relative path
Thus the sendRedirect method of the response
object enables one to forward a request to anew target.
But one must note that if the JSP executing has
already sent page content to the client, then thesendRedirect() method of response object will
not work and will fail.