Thursday, April 16, 2009

Write a program using the request.getParameter() method

Write a program using the request.getParameter() method to enter the Name and Password of a user and display the output on another JSP page.

Solution:
The files used to run the application are:
1. User.jsp
2. UserDisplay.jsp
<html>
<head>
<title>Example of Implicit Objects</title>
</head>
<body>
<h1>User submission form</h1>
<form action="UserDisplay.jsp" method="post">
Enter User Name:
<input type="text" name="uname">
<br>
<br>
Enter Password:
<input type="password" name="pname">
<br>
<br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Save the code as User.jsp in the C:\Tomcat 5.5\Webapps\basic directory
<html>
<head>
<title>Example of Implicit objects</title>
</head>
<body>
<font face=Times New Roman size=3>
Thank you for your submission. Your information has been
successfully added to the database:
<br>
<br>
<%
String sUName = request.getParameter("uname");
String sPName = request.getParameter("pname");
%>
User Name:<%=sUName%><br>
Password:<%=sPName%><br>
</font>
</body>
</html>
Save the code as UserDisplay.jsp in the C:\Tomcat 5.5\Webapps\basic directory.

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

Figure 4.1: Output of User.jsp

The user enters the information and clicks the Submit button. The control is transferred to the UserDisplay.jsp page.
The output of the program is as shown in Figure 4.2.

Figure 4.2: Output of UserDisplay.jsp

3 nhận xét:

Anonymous said...

good work

Anonymous said...

thanx...

saifuctg said...

tanks
www.fatfreeonline.com