Sunday, July 9, 2017

6. Write a JAVA JSP Program which uses jsp:include and jsp:forward action to display a Webpage.

header.jsp

<%@ page import="java.util.Date" %>
<html>
<head>
<title> </title>
</head>
<body>
<h1>
My website. Time:
<% Date d=new Date();%>
<%=d%>
</h1>
</body>
</html>
index.jsp
<html>
<head>
<title>Index Page</title>
</head>
<body>
<center>
<jsp:include page="header.jsp"/>
<br />
<h1>
Enter Data
</h1>
<br />
<form method="post" action="val.jsp">
Username:
<input type="text" name="uname"/>
<br/> password:
<input type="password" name="upass"/>
<br/>
<input type="submit" value="login">
</form>
</center>
</body>
</html>

val.jsp

<% if(request.getParameter("uname").equals("student") &&
request.getParameter("upass").equals("ait")){%>
<jsp:forward page="welcome.jsp" />
<%}
else{ %>
<jsp:forward page="index.jsp" />
<% } %>
welcome.jsp
<!DOCTYPE html>
<html>
<head>
<title>welcome page</title>
</head>
<body bgcolor="pink">
<center>
<jsp:include page="header.jsp"/><br/>
<h1>Welcome Mr./Ms. <%=request.getParameter("uname") %></h1>
</center>
</body>
</html>

No comments:

Post a Comment