JSP第五周作业
1.
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'listenEnglish.jsp' starting page</title> </head> <body bgcolor=cyan> <br>英语课文(English Text): </br> <p style="font-family:宋体;font-size:18;color:black"> <jsp:include page="english/english.txt"></jsp:include> <br>课文音频(English Audio):</br> <jsp:include page="audio.jsp"></jsp:include> </p> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'audio.jsp' starting page</title> </head> <body bgcolor=pink> <embed src="english/english.mp3" autostart=false> 课文音频 </embed> </body> </html>
任务二、教材P45 8题
提示:圆形面积需要一个param 梯形面积需要3个param,可以参考教材例2-11
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'main.jsp' starting page</title> </head> <body> <% double r = 3, a = 2, b = 5, c = 4; %> <br>加载circle.jsp计算半径为<%=r%>的圆的面积: <jsp:include page="circle.jsp"> <jsp:param value="<%=r %>" name="sideR" /></jsp:include> <p>----------------------分割线---------------------------</p> <br>加载ladder.jsp计算上底、下底、高为<%=a%>,<%=b%>,<%=c%>的梯形面积 <jsp:include page="ladder.jsp"> <jsp:param value="<%=a %>" name="sideA" /> <jsp:param value="<%=b %>" name="sideB" /> <jsp:param value="<%=c %>" name="sideC" /> </jsp:include> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <%!public String getArea(double r) { if (r > 0) { double area = r * r * 3.14; return " " + area; } else { return ("半径为" + r + "不能为大于0以外的数字,无法计算面积"); } }%> <% String sideR = request.getParameter("sideR"); double r = Double.parseDouble(sideR); %> <br> <br> 我是被加载的文件,负责计算圆的面积 <br> 给我传递的半径是:<%=r%> <br> 圆的面积是:<%=getArea(r)%> <html> <head> <title>My JSP 'circle.jsp' starting page</title> </head> <body></body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%! public String getArea(double a,double b,double c){ if(a>0&&b>0&&c>0){ double area=(a+b)*c/2; return " "+area; }else{ return("梯形的上底、下底、高"+a+""+b+""+c+"不能为大于0以外的数字,无法计算面积"); } } %> <% 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); %> <br><br>我是被加载的文件,负责计算梯形的面积<br> 给我传递的上底、下底、高是:<%=sideA %>,<%=sideB %>,<%=sideC %> <br>梯形的面积是:<%=getArea(a,b,b) %> <html> <head> <title>My JSP 'ladder.jsp' starting page</title> </head> <body></body> </html>
任务三
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> </head> <body> <table border="1" align="center" bgcolor="yellow"> <tr align="center"><td colspan="2"><jsp:include page="top.jsp"></jsp:include> <tr align="center"> <td><jsp:include page="left.jsp"></jsp:include></td> <td><jsp:include page="main.jsp"></jsp:include></td> <tr align="center"><td colspan="2"><jsp:include page="end.jsp"></jsp:include> </table> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%="main.jsp的文件内容包含在这里 "%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%="top.jsp的文件内容包含在这里 "%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%="end.jsp的文件内容包含在这里 "%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%="left.jsp的文件内容包含在这里 "%>
任务四
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> </head> <body> <% int i = (int) (Math.random() * 10 + 1); if (i % 2 == 0) { %> <jsp:forward page="one.jsp"> <jsp:param value="<%=i %>" name="num" /> </jsp:forward> <% } else { %> <jsp:forward page="two.jsp"> <jsp:param value="<%=i %>" name="num" /> </jsp:forward> <% } %> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'one.jsp' starting page</title> </head> <body> <% String m = request.getParameter("num"); int n = Integer.parseInt(m); out.print("随机数为" + n + "<br>"); %> Hello,我是一个奇数! </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'two.jsp' starting page</title> </head> <body> <% String m = request.getParameter("num"); int n = Integer.parseInt(m); out.print("随机数为" + n + "<br>"); %> Hello,我是一个偶数! </body> </html>