猜数字游戏
来源:互联网 发布:java的设计模式 编辑:程序博客网 时间:2024/06/06 05:11
number.jsp
<%@page contentType="text/html; charset=utf-8"%><html><body><p>随机分配了1到100之间的数:<% int number =(int)(Math.random()*100)+1;session.setAttribute("count", new Integer(0));session.setAttribute("save", new Integer(number)); %> <p>输入你所猜的数 <form action="result.jsp" method="post" name="form"><input type="text" name="number" ><input type="submit" value="提交" name="submit"></form></body></html>
result.jsp
<%@page contentType="text/html; charset=utf-8"%><% String str=request.getParameter("number"); if(str==null){ str="0"; } int guessNumber = Integer.parseInt(str); Integer integer =(Integer)session.getAttribute("save"); int realnumber =integer.intValue(); if(guessNumber==realnumber){ int n = ((Integer)session.getAttribute("count")).intValue(); n=n+1; session.setAttribute("count", new Integer(n)); response.sendRedirect("success.jsp"); }else if(guessNumber>realnumber){ int n = ((Integer)session.getAttribute("count")).intValue(); n=n+1; session.setAttribute("count", new Integer(n)); response.sendRedirect("large.jsp"); }else if(guessNumber>realnumber){ int n = ((Integer)session.getAttribute("count")).intValue(); n=n+1; session.setAttribute("count", new Integer(n)); response.sendRedirect("small.jsp"); }%>
large.jsp
<%@page contentType="text/html; charset=utf-8"%><html><body><p>您所猜数过大,请再猜!<form action="number.jsp" method="post" ><input type="submit" value="点击返回"></body></html>
small.jsp
<%@page contentType="text/html; charset=utf-8"%><html><body><p>您所猜数过小,请再猜!<form action="number.jsp" method="post" ><input type="submit" value="点击返回"></body></html>
success.jsp
<%@page contentType="text/html; charset=utf-8"%><html><body><p>您猜对了<form action="number.jsp" method="post" ><input type="submit" value="点击返回"></body></html>
- 游戏_猜数字
- 猜数字游戏
- 猜数字游戏
- 猜数字游戏源码
- 猜数字游戏
- 猜数字游戏
- python猜数字游戏
- 猜数字游戏
- 猜数字游戏
- 猜数字游戏
- 猜数字游戏
- 猜数字游戏
- 猜数字游戏
- 关于猜数字游戏
- 猜数字游戏实现
- 猜数字游戏
- 模拟猜数字游戏
- 猜数字游戏
- linux内核数据结构---hash表
- JQuery添加到Eclipse中编写代码时没有提示信息
- JCS入门指南
- IE6下实现Width:auto
- 异常处理、日志处理等问题
- 猜数字游戏
- Study Flex《Out of memory-cannot load design mode》
- c/c++使用gsoap发布和调用webservice
- KillTimer的用法(百度百科)
- python写代码生成脚本
- 数据结构与算法(一)LinearList ADT
- 设计模式六大原则(1):单一职责原则
- linux获取mac地址
- c/c++使用gsoap调用wcf发布的webservice