1. Trang chủ
  2. » Công Nghệ Thông Tin

Dynamic Web Pages using JSP - Lab Deliverable 2 ppt

8 311 3

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 8
Dung lượng 364,43 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

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.. UserDisplay.jsp Example of Implicit Objects

Trang 1

Lab Deliverable 2 Using Java Server Pages (JSP) Tags Part II

1 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

Trang 2

%>

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

Trang 3

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

Figure 4.2: Output of UserDisplay.jsp

2 Write a program that uses the response.setHeader()method to display the date In addition, set the response header attribute and utilize the JSP expression tag

Solution:

1 The file required to run the application is Date.jsp The file is to be saved in C:\Tomcat 5.5\Webapps\basic directory

//Date.jsp

<html>

<head>

<title>Example of JSP Implicit Object</title>

<%@ page import="java.util.Date" %>

</head>

<body bgcolor=#ffffff>

Trang 4

The output of the program is as shown in Figure 4.3

Figure 4.3: Output of Date.jsp

Trang 5

Do It Yourself

1 Write a program to retrieve the name and IP address of a remote computer

Hint: Use the request implicit object to retrieve the values

Solution:

The file used to run the application is IPAdd.jsp The file is to be saved in C:\Tomcat

5.5\Webapps\basic directory

<html>

<head>

<title>System Information</title>

</head>

<body>

<h3>Details of Remote Computer:</h3>

<b>Computer Name:</b>:

<br>

<%=request.getRemoteHost()%>

<br>

<br>

<b>IP Address:</b>:

<br>

<%=request.getRemoteAddr()%>

<br>

</body>

</html>

Trang 6

The output of the program is as shown in Figure 4.4

Figure 4.4: Output of IPAdd.jsp

2 Write a program that passes three parameters to a JSP page In addition, override a request

parameter when a JSP page is called Specify the three parameters as param1, param2 and

param3

Solution:

The files used to run the application are:

1 ParamId.jsp

2 ParamObj.jsp

<html>

<head></head>

<body>

<jsp:include page="ParamObj.jsp" >

<br>

<jsp:param name="param1" value="val1" />

<br>

<jsp:param name="param2" value="val2" />

<br>

<jsp:param name="param3" value="val3" />

</jsp:include>

<br>

<b>Calling page:<b>

Trang 7

Name2: <%= request.getParameter("param2") %>

<br>

Name3: <%= request.getParameter("param3") %>

<br>

</body>

</html>

Save the code as ParamId.jsp in the C:\Tomcat 5.5\Webapps\basic directory

<html>

<body>

<h2>Called page: </h2>

<b>Names:</b>

<br>

Name1: <%= request.getParameter("param1") %>

<br>

Name2: <%= request.getParameter("param2") %>

<br>

Name3: <%= request.getParameter("param3") %>

<br>

</body>

</html>

Save the code as ParamObj.jsp in the C:\Tomcat 5.5\Webapps\basic directory The http://localhost:8080/basic/ParamObj.jsp?param1= Alice&param2=Bob&param3=Cathy path is entered into the Web browser This passes the three parameters Eric, Alice, and Bob to the ParamId.jsp page

Trang 8

The output of the program is as shown in Figure 4.5

Figure 4.5: Output of ParamObj.jsp

Ngày đăng: 14/08/2014, 05:20

TỪ KHÓA LIÊN QUAN

w