Session猜数字游戏
来源:互联网 发布:mac系统怎么登陆steam 编辑:程序博客网 时间:2024/06/07 05:37
inputGuess.jsp
<%-- Created by IntelliJ IDEA. User: matt Date: 2017/4/23 Time: 上午9:37 To change this template use File | Settings | File Templates.--%><%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head> <title>inputGuess</title></head><body bgcolor="#ffc0cb"> <p>随机分配你一个1-100之间的数,请猜测!</p> <% int number = (int)(Math.random() * 100) + 1; session.setAttribute("count", new Integer(0)); session.setAttribute("save", new Integer(number)); %> <form action="result2.jsp" method="post" name="form"> 输入你的猜测:<input type="text" name="boy"> <input type="submit" value="送出" name="submit"> </form></body></html>
result2.jsp
<%-- Created by IntelliJ IDEA. User: matt Date: 2017/4/23 Time: 上午9:40 To change this template use File | Settings | File Templates.--%><%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head> <title>result2</title></head><body> <% String str = request.getParameter("boy"); if (str.length() == 0) { response.sendRedirect("inputGuess.jsp"); } int guessNumber = -1; try { 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 { int n = ((Integer)session.getAttribute("count")).intValue(); n = n + 1; session.setAttribute("count", new Integer(n)); response.sendRedirect("small.jsp"); } } catch (Exception e) { response.sendRedirect("inputGuess.jsp"); } %></body></html>
small.jsp
<%-- Created by IntelliJ IDEA. User: matt Date: 2017/4/23 Time: 上午9:47 To change this template use File | Settings | File Templates.--%><%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head> <title>small</title></head><body> <form action="result2.jsp" method="get" name="form"> 猜小了,请再猜<input type="text" name="boy"> <input type="submit" value="送出" name="submit"> </form></body></html>
large.jsp
<%-- Created by IntelliJ IDEA. User: matt Date: 2017/4/23 Time: 上午9:49 To change this template use File | Settings | File Templates.--%><%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head> <title>large</title></head><body> <form action="result2.jsp" method="get" name="form"> 猜大了,请再猜<input type="text" name="boy"> <input type="submit" value="送出" name="submit"></form></body></html>
success.jsp
<%-- Created by IntelliJ IDEA. User: matt Date: 2017/4/23 Time: 上午9:49 To change this template use File | Settings | File Templates.--%><%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head> <title>success</title></head><body> <% int count = ((Integer)session.getAttribute("count")).intValue(); int num = ((Integer)session.getAttribute("save")).intValue(); %> <p>恭喜您,猜对了</p><br> 你共猜了<%=count%>次,这个数字就是<%=num%><br> <a href="inputGuess.jsp">回到首页</a></form></body></html>
0 0
- Session猜数字游戏
- 运用Session的猜数字游戏
- 利用内置变量session做的猜数字游戏游戏
- 游戏_猜数字
- 猜数字游戏
- 猜数字游戏
- 猜数字游戏源码
- 猜数字游戏
- 猜数字游戏
- python猜数字游戏
- 猜数字游戏
- 猜数字游戏
- 猜数字游戏
- 猜数字游戏
- 猜数字游戏
- 猜数字游戏
- 关于猜数字游戏
- 猜数字游戏实现
- Ubuntu 下同局域网主机访问Tomcat 服务器
- Android项目ViewPager+Fragment的基本使用
- SQLite数据库——案例:商品展示
- 剑指offer 对称的二叉树
- android TextView超链接设置颜色
- Session猜数字游戏
- Elasticsearch的介绍和安装
- C++中虚函数、纯虚函数、抽象类、重载、覆盖、隐藏的区别与联系
- 自己实现的一个smallstring
- linux下同时启动多个tomcat
- 03动态规划-05Edit Distance
- error
- Matlab 图像处理 增加图像亮度(曝光度)算法
- HDU 2473——junk mails