session從第一個頁面傳到第二個
看代碼:
1
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; Charset=gb2312" />
6
<title>無標題文檔</title>
7
</head>
8
9
<body>
10
<form action="" name="form1" method="post">
11
<p>地址:
12
<input type="text" name="useradd" />
13
<br>
14
<br>
15
郵編:
16
<input type="text" name="code" />
17
</p>
18
<p>您的姓名:
19
<input type="text" name="username"/></p>
20
<p>
21
<input type="submit" value="保存" />
22
</p>
23
</form>
24
<%
25
String useradd = request.getParameter("useradd");
26
String code = request.getParameter("code");
27
28
if(useradd!=null){
29
String username = request.getParameter("username");
30
session.setAttribute("csname",username);
31
out.println("您填寫的地址是:"+useradd);
32
out.println("<br><br>");
33
out.println("您填寫的郵編是:"+code);
34
out.println("<p><a href=\"check.jsp\">下一步</a>");
35
}
36
%>
37
38
</body>
39
</html>
40
頁面2:check.jsp
2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

1
<%@ page contentType="text/html; charset=gb2312" language="java" %>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
6
<title>無標題文檔</title>
7
</head>
8
<body>
9
<%
10
String csname=(String)session.getAttribute("csname");
11
out.println(csname);
12
%>
13
14
</body>
15
</html>
16

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

沒有所謂的命運,只有不同的選擇!