資源描述:
《jsp實(shí)現(xiàn)猜數(shù)字游戲》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在應(yīng)用文檔-天天文庫。
1、(1)ex3_index.jsp<%@pagecontentType="text/html;charset=gb2312"%>
MyJSP'ex3_index.jsp'startingpage系統(tǒng)隨機(jī)分配了一個1到100之間的整數(shù),請猜!
輸入你所猜的數(shù):
2、FORM><%intnumber=(int)(Math.random()*100+1);session.setAttribute("count",newInteger(0));//猜數(shù)次數(shù)session.setAttribute("save",newInteger(number));//存儲正確的數(shù)session.setAttribute("minNumber",newInteger(1));//最小值存儲session.setAttribute("maxNumber",newInteger(100));//最大值存儲%>(2)result.jsp<%@page
3、contentType="text/html;charset=gb2312"%>
MyJSP'result.jsp'startingpageThisistheresultpage(hidden).
<%Stringstr=request.getParameter("guess");//從文本框中獲取字符串intguessNumber=Integer.parseInt(str);//將字符串轉(zhuǎn)換成整數(shù)intmax=((Integer)session.getAttribute("maxNumber")).
4、intValue();intmin=((Integer)session.getAttribute("minNumber")).intValue();Integerinteger=(Integer)session.getAttribute("save");intrealnumber=integer.intValue();if(guessNumber==realnumber){intn=((Integer)session.getAttribute("count")).intValue();n=n+1;session.setAttribute("count",newInteger(n));res
5、ponse.sendRedirect("success.jsp");}elseif(guessNumber>realnumber){intn=((Integer)session.getAttribute("count")).intValue();n=n+1;max=guessNumber;session.setAttribute("count",newInteger(n));session.setAttribute("maxNumber",newInteger(max));response.sendRedirect("larger.jsp");}elseif(guessNumber6、lnumber){intn=((Integer)session.getAttribute("count")).intValue();n=n+1;min=guessNumber;session.setAttribute("count",newInteger(n));session.setAttribute("minNumber",newInteger(min));response.sendRedirect("smaller.jsp");}%>(3)larger.jsp<%@pagecontentType="text/html;charset=gb2312"%>7、tml>
MyJSP'larger.jsp'startingpage<%intmax=((Integer)session.getAttribute("maxNumber")).intValue();intmin=((Integer)session.getAttribute("minNumber")).intValue();%>Thisislargerpag