1、看电影 watchMovie.jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body bgcolor=yellow> <h1>用一张10元购买票价是2元的电影票一张。</h1> <% int backMoney = 0; backMoney = 10 - 2; %> <jsp:forward page="change5.jsp"> <jsp:param name="number" value="<%=backMoney %>"/> <jsp:param name="mess" value="" /> </jsp:forward> </body> </html> Change5.jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body bgcolor = cyan> <% request.setCharacterEncoding("gb2312"); String backMoneyStr = request.getParameter("number"); String mess = request.getParameter("mess"); int backMoney = 0; int count = 0; int coin = 5; backMoney = Integer.parseInt(backMoneyStr); while(true){ count ++; if(count * coin > backMoney) break; } backMoney = backMoney - (count - 1) * coin; mess = mess + "<br>找赎" + (count - 1) + "张面值" + coin + "元的钱币"; if(backMoney > 0){ %> <jsp:forward page="change2.jsp"> <jsp:param name="number" value="<%=backMoney %>"/> <jsp:param name="mess" value="<%=mess %>"/> </jsp:forward> <% } else{ out.print("<br>"+mess); %> <br><embed src="movie.mp4" width=300 height=270 autostart="false"> 看电影 </embed> <% } %> </body> </html> Change2.jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body bgcolor = cyan> <% request.setCharacterEncoding("gb2312"); String backMoneyStr = request.getParameter("number"); String mess = request.getParameter("mess"); int backMoney = 0; int count = 0; int coin = 2; backMoney = Integer.parseInt(backMoneyStr); while(true){ count ++; if(count * coin > backMoney) break; } backMoney = backMoney - (count - 1) * coin; mess = mess + "<br>找赎" + (count - 1) + "张面值" + coin + "元的钱币"; if(backMoney > 0){ %> <jsp:forward page="change1.jsp"> <jsp:param name="number" value="<%=backMoney %>"/> <jsp:param name="mess" value="<%=mess %>"/> </jsp:forward> <% } else{ out.print("<br>"+mess); %> <br><embed src="movie.mp4" width=300 height=270 autostart="false"> 看电影 </embed> <% } %> </body> </html> Change1.jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body bgcolor = cyan> <% request.setCharacterEncoding("gb2312"); String backMoneyStr = request.getParameter("number"); String mess = request.getParameter("mess"); int backMoney = 0; int count = 0; int coin = 1; backMoney = Integer.parseInt(backMoneyStr); while(true){ count ++; if(count * coin > backMoney) break; } backMoney = backMoney - (count - 1) * coin; mess = mess + "<br>找赎" + (count - 1) + "张面值" + coin + "元的钱币"; out.print("<br>" + mess); %> <br><embed src="movie.mp4" width=300 height=270 autostart="false"> 看电影 </embed> </body> </html> 2、三角形面积 example.jsp: <%@ page contentType = "text/html" %> <%@ page pageEncoding = "utf-8" %> <html><body bgcolor = cyan> <% double a= 6.12,b = 7.08,c = 9.22; %> <p style= "font-family:宋体;font-size:36"> <br>加载triangle.jsp计算三边为<%= a %>,<%= b %>,<%= c %>的三角形面积。 <jsp:include page = "triangle.jsp"> <jsp:param name = "sideA" value = "<%= a %>"/> <jsp:param name = "sideB" value = "<%= b %>"/> <jsp:param name = "sideC" value = "<%= c %>"/> </jsp:include> </p> </body> </html> triangle.jsp: <%@ page contentType = "text/html" %> <%@ page pageEncoding = "utf-8" %> <%! public String getArea(double a,double b,double c){ if(a+b>c&&a+c>b&&c+b>a){ double p = (a+b+c)/2.0; double area = Math.sqrt((p-a)*(p-b)*(p-c)); String result = String.format("%.2f",area); return result; } else{ return(""+a+","+b+","+c+"不能构成一个三角形,无法计算面积"); } } %> <% String sideA =request.getParameter("sideA"); String sideB =request.getParameter("sideB"); String sideC =request.getParameter("sideC"); double a = Double.parseDouble(sideA); double b = Double.parseDouble(sideB); double c = Double.parseDouble(sideC); %> <p style= "font-family:黑体;font-size:15;color:blue"> <br><b>我是被加载的文件,负责计算三角形的面积<br> 给我传递的三边是:<%= sideA%>,<%= sideB%>,<%= sideC%></b> <br><b><i>三角形的面积(保留2位小数):<%= getArea(a,b,c) %></i></b></i> </p> |
1、看电影 2、三角形面积 |