JSP第五周作业

1.任务一、教材P39实验3

 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%@ page contentType="text/html; charset=UTF-8" %>
 3 <%
 4 request.setCharacterEncoding("UTF-8");
 5 response.setCharacterEncoding("UTF-8");
 6  %>
 7 <!DOCTYPE HTML>
 8 <html>
 9 <head>
10 <meta charset="utf-8">
11 <title>My JSP 'index.jsp' starting page</title>
12 </head>
13 
14 <body bgcolor=cyan>
15     <br>英文课文(English Text):
16     </br>
17     <p style="font-family: 宋体;font-size: 18;color: black">
18         <jsp:include page="english.txt" />
19         <br>课文音频(English Audio):</br>
20         <jsp:include page="audio.jsp" />
21     </p>
22 </body>
23 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <!DOCTYPE HTML>
 3 <html>
 4 <head>
 5 <meta charset="utf-8">
 6 <title>My JSP 'index.jsp' starting page</title>
 7 </head>
 8 
 9 <body bgcolor=pink>
10     <embed src="english.mp3" autostart="false">
11     课文音频
12     </embed>
13 </body>
14 </html>

2.任务二、教材P45  8题

 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <!DOCTYPE HTML>
 3 <html>
 4 <head>
 5 <meta charset="utf-8">
 6 <title>My JSP 'index.jsp' starting page</title>
 7 </head>
 8   
 9   <body>
10     <jsp:include page="circle.jsp">
11     <jsp:param value="5" name="r"/>
12     </jsp:include>
13     <jsp:include page="ladder.jsp">
14     <jsp:param value="4" name="h"/>
15     <jsp:param value="6" name="sd"/>
16     <jsp:param value="3" name="xd"/>
17     </jsp:include>
18   </body>
19 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <!DOCTYPE HTML>
 3 <html>
 4 <head>
 5 <meta charset="utf-8">
 6 <title>My JSP 'index.jsp' starting page</title>
 7 </head>
 8 
 9 <body>
10     <%
11         double r = request.getParameter("r") == null ? 0 : Double
12                 .parseDouble(request.getParameter("r"));
13         double area = 3.14 * r * r;
14         out.print("圆的半径为:" + r + "</br>面积为:" + area);
15         out.print("</br>--------------------------------</br>");
16     %>
17 </body>
18 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <!DOCTYPE HTML>
 3 <html>
 4 <head>
 5 <meta charset="utf-8">
 6 <title>My JSP 'index.jsp' starting page</title>
 7 </head>
 8 
 9 <body>
10     <%
11         double h = request.getParameter("h") == null ? 0 : Double
12                 .parseDouble(request.getParameter("h"));
13         double sd = request.getParameter("sd") == null ? 0 : Double
14                 .parseDouble(request.getParameter("sd"));
15         double xd = request.getParameter("xd") == null ? 0 : Double
16                 .parseDouble(request.getParameter("xd"));
17         double area = ((sd + xd) * h) / 2;
18         out.print("梯形上底:" + sd + "</br>下底:" + xd + "</br>高:" + h
19                 + "</br>面积:" + area);
20     %>
21 </body>
22 </html>

3.任务三

 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <!DOCTYPE HTML>
 3 <html>
 4 <head>
 5 <title>My JSP 'index.jsp' starting page</title>
 6 <meta charset="utf-8">
 7 </head>
 8 
 9 <body>
10     <table border="1" align="center" bgcolor="yellow">
11         <tr align="center">
12             <td colspan="2"><jsp:include page="top.jsp"></jsp:include>
13         <tr align="center">
14             <td><jsp:include page="left.jsp"></jsp:include></td>
15             <td><jsp:include page="right.jsp"></jsp:include></td>
16         <tr align="center">
17             <td colspan="2"><jsp:include page="end.jsp"></jsp:include>
18     </table>
19 </body>
20 </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 <%="left.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 <%="end.jsp的文件内容包含在这里" %>

4.任务四

 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <!DOCTYPE HTML>
 3 <html>
 4 <head>
 5 <meta charset="utf-8">
 6 <title>My JSP 'index.jsp' starting page</title>
 7 </head>
 8 <body>
 9     <%
10         int i = (int) (Math.random() * 10 + 1);
11         if (i % 2 == 0) {
12     %>
13     <jsp:forward page="ou.jsp">
14         <jsp:param value="<%=i %>" name="num" />
15     </jsp:forward>
16     <%
17         } else {
18     %>
19     <jsp:forward page="ji.jsp">
20         <jsp:param value="<%=i %>" name="num" />
21     </jsp:forward>
22     <%
23         }
24     %>
25 </body>
26 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <!DOCTYPE HTML>
 3 <html>
 4 <head>
 5 <meta charset="utf-8">
 6 <title>My JSP 'index.jsp' starting page</title>
 7 </head>
 8 <body>
 9     <%
10         String m = request.getParameter("num");
11         int n = Integer.parseInt(m);
12         out.print("随机数为" + n + "<br>");
13     %>
14     Hello,我是一个奇数!
15 </body>
16 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <!DOCTYPE HTML>
 3 <html>
 4 <head>
 5 <meta charset="utf-8">
 6 <title>My JSP 'index.jsp' starting page</title>
 7 </head>
 8 <body>
 9     <%
10         String m = request.getParameter("num");
11         int n = Integer.parseInt(m);
12         out.print("随机数为" + n + "<br>");
13     %>
14     Hello,我是一个偶数!
15 </body>
16 </html>

 

posted @ 2022-04-03 13:06  Lwk36  阅读(9)  评论(0编辑  收藏  举报