JSP Redirection Small example (not speaking principle)

Source: Internet
Author: User

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)

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.