Thursday, 13 November 2014

jsp response implicit object

response is an implicit object of type HttpServletResponse.
The instance of HttpServletResponse is created by the web container for each jsp request.
We can use this object to set content type, character encoding, header information, adding cookies to response and redirecting the request to other resource.

Example ResponseDemo.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="Start.jsp"> 
<input type="submit" value="go to java-isfun blog"><br/> 
</form> 
</body>
</html>
Start.jsp
<%@ 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%response.sendRedirect("http://java-isfun.blogspot.in"); %>
</body>
</html>
When you will click on the button,it will redirect you to my blog.