Write a JSP page lucknum.jsp, generate a random number between 0-9 as the user lucky number, save it to the session, and redirect to another page showlucknum.jsp , display the user's lucky numbers in this page
lucknum.jsp
<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title><!--<script type= "Text/javascript" >/* Generate random number */function fun () {int num = Math.Round (math.random () *9); }</script> -</Head><Body><% //Get Lucky NumbersDoubleNum=math.random ()*Ten; LongLucknum=math.round (num); Session.setattribute ("Lucknum", Lucknum); Response.sendredirect ("two.jsp"); %></Body></HTML>
showlucknum.jsp
<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body><% ObjectLucknum=Session.getattribute ("Lucknum"); if(Lucknum.tostring (). Equals ("5") {out.print ("congratulations on winning the lottery, the numbers are:"+lucknum.tostring ()); }Else{out.print ("no jackpot, the numbers are:"+lucknum.tostring ()); } %></Body></HTML>
JSP Redirection Small example (not speaking principle)