思路:1.第一个是随机产生的数字,告诉我们去猜 cai.jsp
2.第二个是一个form表单,提交按钮后,将连接到验证页面 test1.jsp
3.第三个是比较猜的数和随机数。对了,提示再玩一次,不对则继续猜。用一个超链接 test2.jsp
老师的思路越来越难搞了。怎么写啊,用到hashMap时候
cai.jsp
1
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 |
<%@ page language= "java"
import = "java.util.*"
pageEncoding= "gb2312" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > <html> <head> <title>My JSP ‘cai.jsp‘
starting page</title> <meta http-equiv= "pragma"
content= "no-cache" > <meta http-equiv= "cache-control"
content= "no-cache" > <meta http-equiv= "expires"
content= "0" > <meta http-equiv= "keywords"
content= "keyword1,keyword2,keyword3" > <meta http-equiv= "description"
content= "This is my page" > <!-- <link rel= "stylesheet"
type= "text/css"
href= "styles.css" > --> </head> <body> <% int
number=( int )(Math.random()* 100 ); session.setAttribute( "number" ,number); %> <a href= "test1.jsp" > 去猜数字---》》开始</a> </body> </html> |
test1.jsp
1
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 |
<%@ page language= "java"
import = "java.util.*"
pageEncoding= "gb2312" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > <html> <head> <title>My JSP ‘test1.jsp‘
starting page</title> <meta http-equiv= "pragma"
content= "no-cache" > <meta http-equiv= "cache-control"
content= "no-cache" > <meta http-equiv= "expires"
content= "0" > <meta http-equiv= "keywords"
content= "keyword1,keyword2,keyword3" > <meta http-equiv= "description"
content= "This is my page" > <!-- <link rel= "stylesheet"
type= "text/css"
href= "styles.css" > --> </head> <body> <form action= "test2.jsp" > <input type= "text"
name= "guess" /> <input type= "submit"
value= "guess" /> </form> </body> </html> |
test2.jsp
1
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 |
<%@ page language= "java"
import = "java.util.*"
pageEncoding= "gb2312" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > <html> <head> <title>My JSP ‘test2.jsp‘
starting page</title> <meta http-equiv= "pragma"
content= "no-cache" > <meta http-equiv= "cache-control"
content= "no-cache" > <meta http-equiv= "expires"
content= "0" > <meta http-equiv= "keywords"
content= "keyword1,keyword2,keyword3" > <meta http-equiv= "description"
content= "This is my page" > <!-- <link rel= "stylesheet"
type= "text/css"
href= "styles.css" > --> </head> <body> <% Integer str1=(Integer)session.getAttribute( "number" ); String str2=request.getParameter( "guess" ); int
num1=Integer.valueOf(str1); int
num2=Integer.parseInt(str2); if (num1==num2){ out.print( "您猜对了---再玩一次 <a href=‘test1.jsp‘>guess</a>" ); } else
if (num1>num2){ out.print( "您猜小了---<a href=‘test1.jsp‘>guess</a>" ); } else { out.print( "您猜大了---<a href=‘test1.jsp‘>guess</a>" ); } %> </body> </html> |
java web 程序---猜数字游戏,布布扣,bubuko.com
原文:http://www.cnblogs.com/langlove/p/3706300.html