.


Divya

JSP response implicit object with example


Response implicit object is mainly used for send response to the client browser after processing the request.

Example:

Suppose a user login with his user id and password, If he enter correct user id and password then it give a success message. In the other hand if he enter incorrect user id and password then it give error message.

Example of JSP Response implicit object

index.html

<!DOCTYPE html>
<html>
<head>
<title>JSP Session</title>
</head>
<body>
<form action="process.jsp">
<input type="text" placeholder="User id" name="userid"> <br><br>
<input type="text" placeholder="Password" name="password"> <br> <br>
<input type="submit" value="submit"><br>
</form>
</body>
</html>

process.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP Session</title>
</head>
<body>
<%
String userid=request.getParameter("userid");
String password=request.getParameter("password");
if(userid.equals("admin") && password.equals("admin123"))
{
response.sendRedirect("success.jsp");
}
else {
response.sendRedirect("error.jsp");
}
%>
</body>
</html>

sucess.jsp

<!DOCTYPE html>
<html>
<head>
<title>you are Sucessfully logged In</title>
</head>
<body>
<p>Sucess</p>
</body>
</html>

error.jsp

<!DOCTYPE html>
<html>
<head>
<title>Error</title>
</head>
<body>
<p>Error</p>
</body>
</html>

Output

JSP Response
Resonse
JSP Request Implicit

If you put worng userid and password then the output is.

Request Implicit

.