Advertisement
Methods | Description |
---|---|
void addCookie(Cookie cookie) | This method adds a Cookie to the response and sent it to browser. |
void addHeader(String name, String value) | This method adds a response header with a name and its value. |
void addDateHeader(String name, long date) | This method adds a response date header with a name and its date value. |
void addIntHeader(String name, int value) | This method adds a response header with a name and its int value. |
void sendError(int sc, String message) | This method sends an error response to client using a status code and a message. |
void sendRedirect (String url) | This method sends a temporary redirect response to client by specifying the URL. |
String setStatus(int sc) | This method sets the status code of the response. |
void setHeader(String name, String value) | This method sets the response header with a name and value. |
void setDateHeader(String name, long date) | This method sets the response header with a name and a date value. |
void setIntHeader(String name, int value) | This method sets the response header with a name and an int value. |
void setContentType(String contentType) | This method adds a MIME type to a response header. |
String getHeader(String name) | This method gets the value of the response header with the given name.. |
<html>
<head>
<title>Using JSP built-in response object</title>
</head>
<body>
<h2>Setting the contentType using response object - </h2>
<% response.setContentType("text/xml"); %>
This page will now be displayed in XML form to the user. <br/>
<i>Thank you for reading</i> <br/>
<b>Have a nice day!</b> <br/>
</body>
</html>
Advertisement
<html>
<head>
<title>Using response object to set cookies </title>
</head>
<body>
<h2>Using the response object to add a cookie in the browser.</h2>
<%
Cookie cookie = new Cookie("Website", "DecodeJava.com");
response.addCookie(cookie);
%>
To read value in cookie, click here <a href="ReadCookie.jsp">Read Cookie</a>
</body>
</html>
<html>
<head>
<title>Ceating a JSP Cookie </title>
</head>
<body>
<h2>Reading the cookies set by the request object.</h2>
<%
Cookie[] array = request.getCookies();
for(int i=0; i<array.length; i++)
{
if(array[i].getName().equals("Name"))
{
out.println("<br/>");
out.println("Name of the cookie : " + array[i].getName() + "<br/>");
out.println("Value in cookie : " + array[i].getValue());
}
}
%>
</body>
</html>
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement