第3次作业

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 '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 = red>
  <embed src = "english/english.mp3" autostart=false>
  课文音频
    </embed>
  </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 = red>
  <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 'test02.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>
    <%!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 'test03.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>
     <%!double getarea(double s,double x,double g){
           double area=(s+x)*g/2;
           return area;
   } %>
   <%
   String string=request.getParameter("s");
   double s1=Double.parseDouble(string);
   string=request.getParameter("x");
   double x1=Double.parseDouble(string);
   string=request.getParameter("g");
   double g1=Double.parseDouble(string);
   double area=getarea(s1, x1, g1);
   
   out.print("梯形的上底是"+s1+"下底是"+x1+"高是"+g1+"面积是"+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+"/";
%>
 <%!double r=(int)(Math.random()*10)+1; %>
<jsp:include page="test02.jsp">
<jsp:param name="r" value="7"/>
</jsp:include>
<br>
<jsp:include page="test03.jsp">
<jsp:param name="s" value="7"/>
<jsp:param name="x" value="7"/>
<jsp:param name="g" value="7"/>
</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>

1.应用表格对页面进行布局(可以借助于Dreamweaver 制作页面框架),如下图所示。表格中显示的文件内容为使用include指令引入相应的JSP文件(JSP文件的内容不限)。

<%@ 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="red">
  <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>
  


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%="bottom.jsp"%>
  


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%="left.jsp"%>
  


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%="right.jsp"%>
  

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%="top.jsp"%>

 

 

 

 

 

任务四

编写一个JSP文件,在该文件中,应用Math.round(Math.random()*10)生成[0,10]之间的随机整数,然后根据生成的是偶数还是奇数,应用<jsp:forward>动作标记分别跳转到对应的偶数页面和奇数页面。

<%@ 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 'test06.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>
    <% double r=(int)(Math.random()*10)+1;
        if(r%2==0){
         
        %>  
        <jsp:forward page="t1.jsp">
        <jsp:param value="<%=r %>" name="num"/>
        </jsp:forward>   
         
        <% }
        else{%>
         
        <jsp:forward page="t2.jsp">
        <jsp:param value="<%=r %>" name="num"/>
        </jsp:forward>
         
        <% }  %>
  </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 'test07.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>
     <%String r=request.getParameter("num");
   out.print("Hello,我是一个偶数"+r); %>
  </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>
     
  </head>
   
  <body> <%String r=request.getParameter("num");
   out.print("Hello,我是一个奇数"+r); %>
  </body>
</html>

 

 

 

posted @ 2022-04-01 17:06  杨英斌  阅读(10)  评论(0编辑  收藏  举报