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> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body bgcolor = cyan> <br>英文课文(english)</br> <p style = "font-famliy:宋体;font - size:18;color:black"> <jsp:include page = "english/english.txt"/> <br>课文音频(English Audio):</br> <jsp:include page = "audio.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> <head> <base href="<%=basePath%>"> <title>My JSP 'audio.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body bgcolor = blue> <embed src = "english/english.mp3" autostart=false> 课文音频 </embed> </body> </html>
2.任务二、教材P45 8题
<%@ 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> 加载yuan.jsp页面,计算圆的面积 <jsp:include page="yuan.jsp"> <!-- 包含circle.jsp --> <jsp:param value="5" name="r"/> <!-- 传r=5的值 --> </jsp:include> 加载tixing.jsp页面,计算梯形的面积 <jsp:include page="tixing.jsp"> <jsp:param value="4" name="a"/> <jsp:param value="5" name="b"/> <jsp:param value="8" name="h"/> </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+"/"; %> <!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 > <b>被加载的文件,计算梯形的面积</b> <%String a=request.getParameter("a"); String b=request.getParameter("b"); String h=request.getParameter("h"); double a1=Double.parseDouble(a); double b1=Double.parseDouble(b); double h1=Double.parseDouble(h); double Tarea =((a1+b1)*h1/2); out.print("梯形的面积是:"+Tarea); %> </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> <b>被加载的文件,计算圆的面积</b> <%String r=request.getParameter("r"); //得到r的值 string 型 double r1=Double.parseDouble(r); //把r转成double类型 double area =3.14*r1*r1; //定义面积 out.print("圆的面积是:"+area); %> <br> </body> </html>
3.任务三、详见Word图片
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'index.jsp' starting page</title> </head> <body> <table border="1" bordercolor="green"> <tr> <th colspan="2"><%@ include file="top.jsp" %></th> </tr> <tr> <th ><%@ include file="left.jsp" %></th> <th ><%@ include file="right.jsp" %></th> </tr> <tr> <th colspan="2"><%@ include file="bottom.jsp" %></th> </tr> </table> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%= "top" %> <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%= "left" %> <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%= "right" %> <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%= "bottom" %>
4.任务四、详见Word图片
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'index.jsp' starting page</title> </head> <body> <% int i = (int) (Math.random() * 10 + 1); if (i % 2 == 0) { %> <jsp:forward page="number2.jsp"> <jsp:param value="<%=i %>" name="num" /> </jsp:forward> <% } else { %> <jsp:forward page="number1.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>My JSP 'index.jsp' starting page</title> </head> <body> <% String r=request.getParameter("num"); int n=Integer.parseInt(r); out.print(n); %> 是奇数 </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'index.jsp' starting page</title> </head> <body> <% String r=request.getParameter("num"); int n=Integer.parseInt(r); out.print(n); %> 是偶数 </body> </html>