jsp-实现猜数字游戏

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

(1)ex3_index.jsp%@pagecontentType=text/html;charset=gb2312%htmlheadtitleMyJSP'ex3_index.jsp'startingpage/title/headbodyp系统随机分配了一个1到100之间的整数,请猜!/pP输入你所猜的数:FORMaction=result.jspmethod=postname=forminputtype=textname=guessinputtype=submitname=submitvalue=送出/FORM%intnumber=(int)(Math.random()*100+1);session.setAttribute(count,newInteger(0));//猜数次数session.setAttribute(save,newInteger(number));//存储正确的数session.setAttribute(minNumber,newInteger(1));//最小值存储session.setAttribute(maxNumber,newInteger(100));//最大值存储%/body/html(2)result.jsp%@pagecontentType=text/html;charset=gb2312%htmlheadtitleMyJSP'result.jsp'startingpage/title/headbodyPThisistheresultpage(hidden).br%Stringstr=request.getParameter(guess);//从文本框中获取字符串intguessNumber=Integer.parseInt(str);//将字符串转换成整数intmax=((Integer)session.getAttribute(maxNumber)).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));response.sendRedirect(success.jsp);}elseif(guessNumberrealnumber){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(guessNumberrealnumber){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);}%/body/html(3)larger.jsp%@pagecontentType=text/html;charset=gb2312%htmlheadtitleMyJSP'larger.jsp'startingpage/title/headbody%intmax=((Integer)session.getAttribute(maxNumber)).intValue();intmin=((Integer)session.getAttribute(minNumber)).intValue();%Thisislargerpage.brP所猜的数比实际的数大,请再猜:/P从%=min%到%=max%FORMaction=result.jspmethod=getname=formINPUTtype=textname=guessINPUTtype=submitvalue=送出name=submit/FORM/body/html(4)smaller.jsp%@pagecontentType=text/html;charset=gb2312%htmlheadtitleMyJSP'smaller.jsp'startingpage/title/headbody%intmax=((Integer)session.getAttribute(maxNumber)).intValue();intmin=((Integer)session.getAttribute(minNumber)).intValue();%Thisissmallerpage.brP所猜的数比实际的数小,请再猜:/P从%=min%到%=max%FORMaction=result.jspmethod=postname=formINPUTtype=textname=guessINPUTtype=submitvalue=送出name=submit/FORM/body/html(5)success.jsp%@pagecontentType=text/html;charset=gb2312%htmlheadtitleMyJSP'success.jsp'startingpage/title/headbodyThisissuccesspage.br%intcount=((Integer)session.getAttribute(count)).intValue();intnum=((Integer)session.getAttribute(save)).intValue();longstartTime=session.getCreationTime();longendTime=session.getLastAccessedTime();%P恭喜您,猜对了!/PP您共猜了%=count%次/PP用时%=(endTime-startTime)/1000%秒/PP这个数字就是%=num%/PP您必须关掉浏览器才能获得新的数/P/body/html实验结果:

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功