Wednesday, April 15, 2009

Exercises 4 lab 1

Write a program welcoming the user to Online Banking Website. Display a text box and a “Submit” button to the user. Label the text box as “Enter name”. After the user enters the name, a “Welcome” message with the name should be displayed. If the user name is null, display a “Welcome” message to the user.

Solution:
<html>
<head>
<title>Welcome to Online Banking</title>
</head>
<body>
<% String user=request.getParameter("user"); %>
<H3>Welcome <%= (user==null) ? "to Online Banking" : user + " to Online Banking" %>!</H3>
<b>Enter name:</b>
<form method=get>
<input type="text" name="user" size=15>
<input type="submit" value="Submit name">
</form>
</body>
</html>

The output of the program is as shown in Figure 2.4 when the user name has not been entered, that is, user name = null.

Figure 2.4: Output of Welcome.jsp
When the user enters name in the text box and clicks on Submit button, the output appears as shown in Figure 2.5.

Figure 2.5: Output of Welcome.jsp

0 nhận xét: