JSP第三次作业
任务一、教材P39实验3
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <%@ page contentType="text/html"%> 3 4 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 5 <html> 6 <head> 7 8 9 <title>My JSP 'audio.jsp' starting page</title> 10 11 12 </head> 13 14 <body bgcolor=pink> 15 <embed src="english/english.mp3" autostart=false> 16 课文音频 17 </embed> 18 19 </body> 20 </html>
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <%@ page contentType="text/html"%> 3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 4 <html> 5 <head> 6 <title>My JSP 'listenEnglish.jsp' starting page</title> 7 </head> 8 9 <body bgcolor=cyan> 10 <br>英文课文(English Text): 11 </br> 12 <p style="font-family:宋体;font-sizez:18;color:black"> 13 <jsp:include page="english/english.txt"/> 14 <br>课文音频(English Audio):</br> 15 <jsp:include page="audio.jsp" /> 16 </p> 17 </body> 18 </html>
任务二、教材P45 8题
提示:圆形面积需要一个param 梯形面积需要3个param,可以参考教材例2-11
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 3 <html> 4 <head> 5 <title>My JSP 'circle.jsp' starting page</title> 6 </head> 7 <body> 8 <% 9 String r = request.getParameter("r"); 10 double bj = Double.parseDouble(r); 11 double area = 3.14 * bj * bj; 12 out.print("圆形的面积是"+area); 13 %> 14 </body> 15 </html>
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 3 <html> 4 <head> 5 <title>My JSP 'ladder.jsp' starting page</title> 6 </head> 7 8 <body> 9 <% 10 String s = request.getParameter("s"); 11 double high = Double.parseDouble(s); 12 String x = request.getParameter("x"); 13 double xia = Double.parseDouble(x); 14 String g = request.getParameter("g"); 15 double gao = Double.parseDouble(g); 16 double area = (high + xia) * gao / 2.0; 17 out.print("梯形的面积是:"+area); 18 %> 19 </body> 20 </html>
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 3 <html> 4 <head> 5 <title>My JSP 'mian.jsp' starting page</title> 6 </head> 7 8 <body> 9 <jsp:include page="circle.jsp"> 10 <jsp:param value="5" name="r" /> 11 </jsp:include> 12 <br> 13 <jsp:include page="ladder.jsp"> 14 <jsp:param value="3" name="s" /> 15 <jsp:param value="4" name="x" /> 16 <jsp:param value="5" name="g" /></jsp:include> 17 18 </body> 19 </html>
任务三、
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <%="top.jsp"%>
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <%="right.jsp"%>
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <%="bottom.jsp"%>
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <%="left.jsp"%>
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme() + "://" 5 + request.getServerName() + ":" + request.getServerPort() 6 + path + "/"; 7 %> 8 9 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 10 <html> 11 <head> 12 <base href="<%=basePath%>"> 13 14 <title>My JSP 'index.jsp' starting page</title> 15 <meta http-equiv="pragma" content="no-cache"> 16 <meta http-equiv="cache-control" content="no-cache"> 17 <meta http-equiv="expires" content="0"> 18 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 19 <meta http-equiv="description" content="This is my page"> 20 <!-- 21 <link rel="stylesheet" type="text/css" href="styles.css"> 22 --> 23 </head> 24 25 <body> 26 <table border="1" bgcolor="blue" align="center" width="800"> 27 <tr align="center"> 28 <td colspan="2" align="center"><%@include file="top.jsp" %> 29 </td> 30 </tr> 31 <tr align="center"> 32 <td align="center"><%@include file="left.jsp" %> 33 </td> 34 <td align="center"><%@include file="right.jsp" %> 35 </td> 36 </tr> 37 <tr align="center"> 38 <td colspan="2" align="center"><%@include file="bottom.jsp" %> 39 </td> 40 </tr> 41 </table> 42 </body> 43 </html>
任务四、
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme() + "://" 5 + request.getServerName() + ":" + request.getServerPort() 6 + path + "/"; 7 %> 8 9 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 10 <html> 11 <head> 12 <base href="<%=basePath%>"> 13 14 <title>My JSP 'odd.jsp' starting page</title> 15 16 <meta http-equiv="pragma" content="no-cache"> 17 <meta http-equiv="cache-control" content="no-cache"> 18 <meta http-equiv="expires" content="0"> 19 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 20 <meta http-equiv="description" content="This is my page"> 21 <!-- 22 <link rel="stylesheet" type="text/css" href="styles.css"> 23 --> 24 25 </head> 26 <%--奇数 --%> 27 <body> 28 <% 29 String odd = request.getParameter("i"); 30 int j = Integer.parseInt(odd); 31 out.print("随机数" + j); 32 %> 33 是奇数!!! 34 </body> 35 </html>
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme() + "://" 5 + request.getServerName() + ":" + request.getServerPort() 6 + path + "/"; 7 %> 8 9 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 10 <html> 11 <head> 12 <base href="<%=basePath%>"> 13 14 <title>My JSP 'even.jsp' starting page</title> 15 16 <meta http-equiv="pragma" content="no-cache"> 17 <meta http-equiv="cache-control" content="no-cache"> 18 <meta http-equiv="expires" content="0"> 19 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 20 <meta http-equiv="description" content="This is my page"> 21 <!-- 22 <link rel="stylesheet" type="text/css" href="styles.css"> 23 --> 24 <%--偶数 --%> 25 </head> 26 27 <body> 28 <% 29 String even = request.getParameter("i"); 30 int ou = Integer.parseInt(even); 31 out.print("随机数" + ou); 32 %> 33 是偶数!!! 34 35 </body> 36 </html>
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme() + "://" 5 + request.getServerName() + ":" + request.getServerPort() 6 + path + "/"; 7 %> 8 9 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 10 <html> 11 <head> 12 <base href="<%=basePath%>"> 13 14 <title>My JSP 'example2.jsp' starting page</title> 15 16 <meta http-equiv="pragma" content="no-cache"> 17 <meta http-equiv="cache-control" content="no-cache"> 18 <meta http-equiv="expires" content="0"> 19 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 20 <meta http-equiv="description" content="This is my page"> 21 <!-- 22 <link rel="stylesheet" type="text/css" href="styles.css"> 23 --> 24 25 </head> 26 27 <body> 28 <h1>生成[]0,10]之间的随机数</h1> 29 <% 30 int i = (int) (Math.random() * 10) + 1; 31 if (i % 2 == 0) { 32 %> 33 <jsp:forward page="even.jsp"> 34 <jsp:param value="<%=i %>" name="i" /> 35 </jsp:forward> 36 <% 37 } else { 38 %> 39 <jsp:forward page="odd.jsp"> 40 <jsp:param value="<%=i%>" name="i" /> 41 </jsp:forward> 42 <% 43 } 44 %> 45 </body> 46 </html>