javaweb程序---猜数字游戏思路: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">
java valueof
<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<%@ 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"/>
24 25 26 27 28 29 30 31 <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=(Attribute("number");
String Parameter("guess");
int num1=Integer.valueOf(str1);
int num2=Integer.parseInt(str2);
if(num1==num2){
out.print("您猜对了---再玩⼀次 <a href='cai.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>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论