jsp3

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 <%@ 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.任务二、教材P45  8题

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 <%!double r=(int)(Math.random()*10)+1; %>
<jsp:include page="circle.jsp">
<jsp:param name="r" value="4"/>
</jsp:include>
<br>
<jsp:include page="ladder.jsp">
<jsp:param name="a" value="4"/>
<jsp:param name="b" value="4"/>
<jsp:param name="c" value="4"/>
</jsp:include>
<!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>
 
   
   
  </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 'index1.jsp' starting page</title>
  </head>
  <body>
    <%!double getarea(double r){
           double area=3.14*r*r;
           return area;
   } %>
   <%
   String r=request.getParameter("r");
   double r1=Double.parseDouble(r);
   double area=getarea(r1);
   out.print("圆形的半径是"+r+",圆形的面积:"+area);
    %>
  </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 'index1.jsp' starting page</title>
  </head>
  <body>
     <%!double getarea(double a,double b,double c){
           double area=(a+b)*c/2;
           return area;
   } %>
   <%
   String string=request.getParameter("a");
   double s1=Double.parseDouble(string);
   string=request.getParameter("b");
   double x1=Double.parseDouble(string);
   string=request.getParameter("c");
   double g1=Double.parseDouble(string);
   double area=getarea(s1, x1, g1);
   
   out.print("梯形的上底是"+s1+"下底是"+x1+"高是"+g1+"面积是"+area);
    %>
   
  </body>
</html>

 

 3. 任务三:

 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%="bottom.jsp"%>
 3 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 4 <%="left.jsp"%>
 5 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 6 <%="right.jsp"%>
 7 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 8 <%="top.jsp"%>10 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
11 <%
12 String path = request.getContextPath();
13 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
14 %>
15 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
16 <html>
17   <head>
18     <base href="<%=basePath%>">
19     <title>My JSP 'index1.jsp' starting page</title>
20   </head>
21   <body >
22   <table border="1" width="600" align="center" bgcolor="yellow">
23   <tr align="center"><td colspan="2"><%@include file="top.jsp"%></td></tr>
24   <tr align="center"><td><%@include file="left.jsp" %></td><td align="center"><%@include file="right.jsp" %></td></tr>
25   <tr align="center"><td colspan="2"><%@include file="bottom.jsp"%></td></tr>
26   </table>
27    
28   </body>
29 </html>

 

 4.任务四

 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%
 3 String path = request.getContextPath();
 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 5 %>
 6 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 7 <html>
 8   <head>
 9     <base href="<%=basePath%>">
10     <title>My JSP 'index1.jsp' starting page</title>
11   </head>
12   <body>
13   <%
14   String r=request.getParameter("i");
15   int x=Integer.parseInt(r);
16   out.print("随机数为:"+x); %>
17   Hello,我是奇数!!!
18    
19   </body>
20 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%
 3 String path = request.getContextPath();
 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 5 %>
 6 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 7 <html>
 8   <head>
 9     <base href="<%=basePath%>">
10     <title>My JSP 'index1.jsp' starting page</title>
11   </head>
12   <body>
13     <%
14   String r=request.getParameter("i");
15   int x=Integer.parseInt(r);
16   out.print("随机数为:"+x); %>
17     Hello,我是偶数!!!
18   </body>
19 </html>
 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%
 3     String path = request.getContextPath();
 4     String basePath = request.getScheme() + "://"
 5             + request.getServerName() + ":" + request.getServerPort()
 6             + path + "/";
 7 %>
 8 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 9 <html>
10 <head>
11 <base href="<%=basePath%>">
12 <title>My JSP 'index1.jsp' starting page</title>
13 </head>
14 <body>
15     <%
16         int i = (int) (Math.random() * 10 + 1);
17         if (i % 2 == 0) {
18     %>
19     <jsp:forward page="ou.jsp">
20         <jsp:param value="<%=i %>" name="i" />
21     </jsp:forward>
22     <%
23         } else {
24     %>
25     <jsp:forward page="ji.jsp">
26         <jsp:param value="<%=i %>" name="i" />
27     </jsp:forward>
28     <%
29         }
30     %>
31 </body>
32 </html>

 

posted @ 2022-04-03 14:03  韩式小火锅  阅读(25)  评论(0编辑  收藏  举报