JSP Response Implicit Object

Introduction:

1.    response  is an instance of classjavax.servlet.http.HttpServletResponse.  The response object represents the response to the client.
2.     By using this object you can add new cookies, change content type of the page and redirect the response.

Methods of response Object:

There are numerous methods available for response object. Some of them are:

1.setContentType()
setContentType method of response object is used to set the MIME type and character encoding for the page.
2.addCookie(Cookie cookie)
addCookie method of response object is used to add the specified cookie to the response.
3.addHeader(String name, String value)
addHeader method of response object is used to write the header as a pair of name and value to the response.
4.containsHeader(String name)
containsHeader method of response object is used to check whether the response already includes the header given as parameter.
5.setHeader(String name, String value)
setHeader method of response object is used to create an HTTP Header with the name and value given as string.
6.sendRedirect(String)
sendRedirect method of response object is used to send a redirect response to the client temporarily by making use of redirect location URL given in parameter.
7.sendError(int status_code)
sendError method of response object is used to send an error response to the client containing the specified status code given in parameter.

Example: test.jsp

<%@ page language="java" %>
<%
response.setContentType("text/html");
response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
out.print("Is cache-controle available :"+response.containsHeader("Cache-Control"));
%>
<html>
<head>
<title>Response object in cache controlling</title>
</head>
</html>



Thanks For Making This Possible! Kindly Bookmark and Share it.

Technorati Digg This Stumble Stumble Facebook Twitter

No comments:

Post a Comment