jsp第三次作业

1. p39 实验3

  

复制代码
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 2 
 3 <!DOCTYPE HTML>
 4 <html>
 5   <head>
 6     
 7     <title>My JSP 'listenEnglish.jsp' starting page</title>
 8     
 9     <meta http-equiv="pragma" content="no-cache">
10     <meta http-equiv="cache-control" content="no-cache">
11     <meta http-equiv="expires" content="0">    
12     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
13     <meta http-equiv="description" content="This is my page">
14     <!--
15     <link rel="stylesheet" type="text/css" href="styles.css">
16     -->
17 
18   </head>
19   
20   <body>
21    <br>英文课文(English Text):</br>
22    <p style="font-family:宋体;font-size:18;color:black">
23    <jsp:include page="english.txt" />
24    <br>课文音频(English Audio):</br>
25    <jsp:include page="audio.jsp" />
26    </p>
27   </body>
28 </html>
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 2 <%@ page contentType = "text/html" %>
 3 <%
 4 String path = request.getContextPath();
 5 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 6 %>
 7
 8 <!DOCTYPE HTML>
 9 <html>
10   <head>
11 <meta charset="utf-8"/>
12    
13     <title>My JSP 'audio.jsp' starting page</title>
14
15
16   </head>
17  
18   <body>
19     <embed src="english.mp3"autostart="false">
20     课文音频
21     </embed>
22   </body>
23 </html>

  

 

 2. P48 8.

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2
 3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 4 <html>
 5   <head>
 6     <title>main.jsp</title>
 7   </head>
 8   <body>
 9     <%
10         double r=7,a=5,b=7,c=6;
11      %>
12      <br>加载circle.jsp计算半径为<%=r %>的圆的面积:
13      <jsp:include page="circle.jsp">
14          <jsp:param value="<%=r %>" name="sideR"/>
15      </jsp:include>
16      <p>------------------------------------------------------------------------------</p>
17      <br>加载ladder.jsp计算上底、下底、高为<%=a %><%=" |"%><%=b %><%=" |"%><%=c %>的梯形面积:
18      <jsp:include page="ladder.jsp">
19          <jsp:param value="<%=a %>" name="sideA"/>
20          <jsp:param value="<%=b %>" name="sideB"/>
21          <jsp:param value="<%=c %>" name="sideC"/>
22      </jsp:include>
23   </body>
24 </html>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%!
 3     public String getArea(double r){
 4         if(r>0){
 5             double area = r*r*3.14;
 6             return ""+area;
 7         }else{
 8             return("半径为"+r+"不能为大于0以外的数字,无法计算面积");
 9         }
10        
11     }
12  %>
13 <%
14     String sideR = request.getParameter("sideR");
15     double r = Double.parseDouble(sideR);
16  %>
17 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
18 <html>
19   <head>
20     <title>circle.jsp</title>
21   </head>
22   <body>
23     <br><br>我是被加载的文件,负责计算圆的面积<br>
24             给我传递的半径是:<%=r %><br>
25                圆的面积是:<%=getArea(r) %>
26   </body>
27 </html>
复制代码

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%!
 3     public String getArea(double a,double b,double c){
 4         if(a>0 && b>0 && c>0){
 5             double area=(a+b)*c/2;
 6             return ""+area;
 7         }else{
 8             return("梯形的上底、下底、高"+a+" "+b+" "+c+"不能为大于0以外的数字,无法计算面积");
 9            
10         }
11     }   
12  %>
13 <%
14     String sideA = request.getParameter("sideA");
15     String sideB = request.getParameter("sideB");
16     String sideC = request.getParameter("sideC");
17     double a = Double.parseDouble(sideA);
18     double b = Double.parseDouble(sideB);
19     double c = Double.parseDouble(sideA);
20  %>
21 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
22 <html>
23   <head>
24     <title>ladder.jsp</title>
25   </head>
26   <body>
27     <br><br>我是被加载的文件,负责计算梯形的面积<br>
28                 给我传递的上底、下底、高是:<%=sideA %><%=" |"%><%=sideB %><%=" |"%><%=sideC %><br>
29                 梯形的面积是:<%=getArea(a,b,c) %>
30   </body>
31 </html>

 

 

3.

.

 

 

任务3:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<%@ 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 'index1.jsp' starting page</title>
  </head>
  <body >
  <table border="1" width="600" align="center" bgcolor="yellow">
  <tr align="center"><td colspan="2"><%@include file="top.jsp" %></td></tr>
  <tr align="center"><td><%@include file="left.jsp" %></td><td align="center"><%@include file="right.jsp" %></td></tr>
  <tr align="center"><td colspan="2"><%@include file="bottom.jsp" %></td></tr>
  </table>
     
  </body>
</html>

 

1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 
3 end.jsp的文件包含在这里
1
2
3
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2
3 left.jsp的文件包含在这里
1
2
3
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2
3 main.jsp的文件包含在这里
1
2
3
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2
3 top.jsp的文件包含在这里

  

 

 

4.

.

 

 

 任务4:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<%@ 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 'index.jsp' starting page</title>
 
</head>
 
<body>
    <%
        int i = (int) (Math.random() * 10 + 1);
        if (i % 2 == 0) {
    %>
 
    <jsp:forward page="ou.jsp">
        <jsp:param value="<%=i%>" name="num" />
    </jsp:forward>
    <%
        } else {
    %>
    <jsp:forward page="ji.jsp">
        <jsp:param value="<%=i%>" name="num" />
    </jsp:forward>
    <%
        }
    %>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<%@ 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 'index.jsp' starting page</title>
 
</head>
 
<body>
    <%
        int i = (int) (Math.random() * 10 + 1);
        if (i % 2 == 0) {
    %>
 
    <jsp:forward page="ou.jsp">
        <jsp:param value="<%=i%>" name="num" />
    </jsp:forward>
    <%
        } else {
    %>
    <jsp:forward page="ji.jsp">
        <jsp:param value="<%=i%>" name="num" />
    </jsp:forward>
    <%
        }
    %>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2
 3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 4 <html>
 5   <head>
 6     <title>偶数</title>
 7   </head>
 8   <body>
 9     <table border="1">
10         <tr><th>Hello,我是一个奇数</th></tr>
11     </table>
12   </body>
13 </html>

 

 

posted @ 2022-07-03 21:58  欧阳晨  阅读(16)  评论(0编辑  收藏  举报