思路:1.第一个是随机产生的数字,告诉我们去猜 cai.jsp
2.第二个是一个form表单,提交按钮后,将连接到验证页面 test1.jsp
3.第三个是比较猜的数和随机数。对了,提示再玩一次,不对则继续猜。用一个超链接 test2.jsp
老师的思路越来越难搞了。怎么写啊,用到hashMap时候
cai.jsp
<%@ 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
<%@ 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
<%@ 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='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>