jsp+servlet实现猜数字游戏(jsp+servlet项目)硬核推荐

随心笔谈2年前发布 编辑
151 0
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买


import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class HandleGuess extends HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
request.setCharacterEncoding(“utf-8”);
response.setContentType(“text/html;charset=utf-8”);
PrintWriter out=response.getWriter();
//获取客户猜测提交的数
int guessNumber=Integer.parseInt(request.getParameter(“guessnumber”));
//获取客户的会话对象
HttpSession session=request.getSession();
Integer integer=(Integer)session.getAttribute(“saveNumber”);
int realNumber=integer.intValue();
System.out.println(realNumber);
System.out.println(guessNumber);
if(guessNumber>realNumber){
session.setAttribute(“message”, “您猜大了”);
System.out.println(“您猜大了—no”);
response.sendRedirect(“inputNumber.jsp”);
}
else if(guessNumber<realNumber){
session.setAttribute(“message”, “您猜小了”);
System.out.println(“您猜小了—no”);
response.sendRedirect(“inputNumber.jsp”);
}
else{
session.setAttribute(“message”, “您猜对了”);
System.out.println(“您猜对了”);
response.sendRedirect(“inputNumber.jsp”);
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}

}

© 版权声明

相关文章