Friday, April 17, 2009

Build a login page for online banking, accepting the user name and password.

1.Build a login page for online banking, accepting the user name and password. Use declarations to define the string variables. Include Java code in the scriptlet block to assign the details to the string variables entered by the user.

Solution:
The file used in this exercise is Expression_Login.jsp. The file is saved in basic directory.
<html>
<head>
<title>Login Page</title>
</head>
<body bgcolor="white">
<%if(request.getParameter("userid")==null&& request.getParameter("password")==null ) { %>
<center>
<h2>Online Banking Login</h2>
</center>
<form method="GET" action="http://localhost:8080/basic/Login.jsp">
<b>User Id:</b> <input type="text" name="userid" size=15>
<p>
<b>Password:<b> <input type="password" name="password" size=8>
<p>
<input type="submit" value="LOGIN">
</form>
<% } else { %>
<%! String userid,password; %>
<%
userid = request.getParameter("userid");
password = request.getParameter("password");
%>
<% } %>
</body>
</html>

The output of the program is as shown in Figure 6.3.

Figure 6.3: Output of Login.jsp

2.Use the above code and greet the login user. Make use of the expression elements to display the message.

Solution:
The file used in this exercise is Login.jsp. The file is saved in basic directory.
<html>
<head>
<title>Login Page</title>
</head>
<body bgcolor="white">
<%if(request.getParameter("userid")==null&& request.getParameter("password")==null ) { %>
<center>
<h2>Online Banking Login</h2>
</center>
<form method="GET" action="http://localhost:8080/basic/Login.jsp">
<b>User Id:</b> <input type="text" name="userid" size=15>
<p>
<b>Password:<b> <input type="password" name="password" size=8>
<P>
<input type="submit" value="LOGIN">
</form>
<% } else { %>
<%! String userid,password; %>
<%
userid = request.getParameter("userid");
password = request.getParameter("password");
%>
<p>
<b>Good Morning!! <%= userid %><p></b>
<% } %>
</body>
</html>

The output of the program is as shown in Figure 6.4.

Figure 6.4: Output of Login.jsp

0 nhận xét: