page1.jpg:
1 <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%> 2 <html> 3 <head> 4 <title></title> 5 </head> 6 7 <body> 8 <img src="images/xxx.png" height="300"> 9 <p>猜电影票价格</p> 10 <% 11 session.setAttribute("number",49); 12 %> 13 <form action="page2.jsp" method="post"> 14 <input type="text" name="guess"/> 15 <input type="submit" value="guess"/> 16 </form> 17 </body> 18 </html>
page2.jsp:
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 <html> 3 <head> 4 <title>guess</title> 5 </head> 6 <body> 7 <% 8 Integer str1=(Integer)session.getAttribute("number"); 9 String str2=request.getParameter("guess"); 10 int num1=Integer.valueOf(str1); 11 int num2=Integer.parseInt(str2); 12 if(num1==num2){ 13 out.print("您猜对了"); 14 }else if(num1>num2){ 15 out.print("您猜小了---<a href='page1.jsp'>guess</a>"); 16 }else{ 17 out.print("您猜大了---<a href='page1.jsp'>guess</a>"); 18 } 19 %> 20 </body> 21 </html>