jsp-a simple guess little game

Source: Internet
Author: User

<%@ Page Language="Java"Import="java.util.*"pageencoding="Utf-8"%><%StringPath=Request.getcontextpath ();StringBasePath=Request.getscheme ()+"://"+Request.getservername ()+":"+Request.getserverport ()+Path+"/";%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"><HTML>  <Head>    <Basehref= "<%=basePath%>">        <title>My JSP ' game.jsp ' starting page</title>        <Metahttp-equiv= "Pragma"content= "No-cache">    <Metahttp-equiv= "Cache-control"content= "No-cache">    <Metahttp-equiv= "Expires"content= "0">        <Metahttp-equiv= "keywords"content= "Keyword1,keyword2,keyword3">    <Metahttp-equiv= "description"content= "This is my page">    <!--<link rel= "stylesheet" type= "Text/css " href= "Styles.css" > -  </Head>    <Body>    <%!intCount= 0;%>    <%        Objectobj=Session.getattribute ("Numint");//when the first visit is NULL, there is a value after the second accessif(obj== NULL) {Random R= NewRandom (); Obj=R.nextint ( -); Session.setattribute ("Numint", obj); }        intRM= Integer. parseint (Obj.tostring ()); %>    <%        StringNumstr=Request.getparameter ("Num");//get the number of guessesintcou=0; if(numstr! )= NULL && !"". Equals (NUMSTR)) {//Direct Browser URL Access Jsp,num value is null, when committed, no value for NUM is entered, num value is""            //num must have a value of Count++; Cou=count; intNum= Integer. parseint (NUMSTR); if(Num>RM) {Out.println ("it's too big."); } Else if(Num<RM) {Out.println ("it's too small."); } Else{out.println ("finally guessed it right."); Random R= NewRandom (); Obj=R.nextint ( -); Session.setattribute ("Numint", obj); Count=0; }                    }    %>you are welcome to play the game of guessing, guess<%=cou%>Times<%--<%out.print (RM);--%>    <formAction= "game.jsp"Method= "POST">        <BR>Enter a number<inputname= "num"> <inputtype= "Submit"value= "Click to confirm">    </form>  </Body></HTML>

Run:

jsp-a simple guess little game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.