JSP第五周作业
1.任务一、教材P39实验3
<%@ 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><body bgcolor=cyan> <br> 英文课文(English Text): <p style="font- family:宋体;font-size:18;color:black"> <jsp:include page="english/english.txt"/> <br>课文音频(English Audio):<br> <jsp:include page ="MyJsp2.jsp"/> </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><body bgcolor=pink> <embed src="english/english.mp3"autostart=false type="application/octet-stream"> 课文音频<embed></body> </html>
2.任务二、教材P45 8题
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>main.jsp page</title> </head> <body> <% double r = 4, a = 5, b = 6, c = 7; %> <jsp:include page="circle.jsp"> <jsp:param value="<%=r %>" name="sideR" /></jsp:include> <br> <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); %> 圆的半径是:<%=r%><br> 圆的面积是:<%=getArea(r)%> <html> <head> <title>circle.jsp 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); %> 梯形的上底、下底、高是:<%=sideA %>,<%=sideB %>,<%=sideC %> <br>梯形的面积是:<%=getArea(a,b,b) %> <html> <head> <title>ladder.jsp page</title> </head> <body></body> </html>
3.任务三、详见Word图片
<%@ 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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> <style type="text/css"> td{ /* margin: auto; */ width: 200px; text-align:center; background: yellow; } tr{ width:400px; height:50px; } td,tr,table{ border: 1px solid red; } </style> </head> <body> <table> <tr> <td id="top" colspan="2"><jsp:include page="top.jsp"></jsp:include></td> </tr> <tr> <td id="left"><jsp:include page="left.jsp"></jsp:include></td> <td id="main"><jsp:include page="main.jsp"></jsp:include></td> </tr> <tr> <td id="end" colspan="2"><jsp:include page="end.jsp"></jsp:include></td> </tr> </table> </body> </html>
<%@ 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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> top.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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> left.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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> main.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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> end.jsp文件
4.任务四、详见Word
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>index.jsp page</title> </head> <body> <% int i = (int) (Math.random() * 10 + 1); if (i % 2 == 0) { %> <jsp:forward page="first.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"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>first.jsp 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"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title> two.jsp page</title> </head> <body> <% String m =request.getParameter("num"); int n = Integer.parseInt(m); out.print("随机数为"+n+"<br>"); %> hello 我是一个奇数! </body> </html>