==========
<html>
<head>
<title>get Request Demo </title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="first.jsp" >
<p>Please enter your name : <input type="text" name="suserName" ></p>
<p>Please enter your address : <input type="text" name="saddress" ></p>
<p>Please enter your Age : <input type="text" name="sage" ></p>
<p><input type="submit" value="Submit" ></p>
</form>
</body>
</html>
first.jsp
==========
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
out.println("first servlet");
String name = request.getParameter("suserName");
String addr = request.getParameter("saddress");
String ag = request.getParameter("sage");
int age = Integer.parseInt(ag);
out.println("<br /><br />");
if(name.endsWith("kumar")){
RequestDispatcher rd=request.getRequestDispatcher("second.jsp");
rd.forward(request, response);
}else{
response.sendRedirect("error.jsp");
}
out.println("<br/><br/>");
out.println("first servlet");
%>
</body>
</html>
second.jsp
==========
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html">
<title>JSP Page</title>
</head>
<body>
<%
String name = request.getParameter("suserName");
String address = request.getParameter("saddress");
String age = request.getParameter("sage");
int ag = Integer.parseInt(age);
out.println("<br /><br />");
out.println("Hi "+name +" Please come and collect your pub pass by paying 1000 rupees");
out.println("<br/><br/>");
%>
</body>
</html>
error.html
==========
Hi, You are not eligible for this Task.
No comments:
Post a Comment