jsp第二周作业

1.p39 实验2 显示当前时间,并输出上午(0-12)好,下午好(13-17),晚上好(18-23)

 <%@ 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>
    <script>
       var userTime = new Date();
       var hour = userTime.getHours();
       var minute = userTime.getMinutes();
       var second = userTime.getSeconds();
       var millisecond = userTime.getMilliseconds();
       document.write("<h2>浏览时间:"+hour+":"+minute+":"+second+":"+millisecond+"<br></h2>"); 
    </script>
    <%
//java注释 Date date= new Date(); date.getHours(); if(date.getHours()>=0&&date.getHours()<=12){ out.print(date+"早上好"); }else if(date.getHours()>=13&&date.getHours()<=17){ out.print(date+"中午好"); }else{ out.print(date+"下午好"); }; %> <br> </body> </html>

 

 

 


2. 使用声明方法,在页面调用该方法,判断2023是不是闰年

<%@ 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 'MyJsp.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 Run(int year){
       if(year%4==0&&year%100!=0||year%400==0){
       return year+"是闰年";
       }else{
       return year+"不是闰年";
       }
       }
      %>
      <% String y=Run(2023);
         out.print(y);
      %>
       
  </body>
</html>

  

 


3.表达式+程序段 循环输出5条hr,长度分别为100px-500px
<hr width="<%=i%>"

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


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>My JSP 'index1.jsp' starting page</title>
</head>
<body>
    <%--jsp注释 --%>
    <%
        for (int i = 1; i <= 5; i++) {
    %>
    <hr width="<%=i * 100%>px">
    <%
        }
    %>

</body>
</html>

  

 


4.在第一题上加Java注释,第二题加html注释,第三题加jsp注释

 

posted @ 2022-03-20 12:49  袁祥凤  阅读(25)  评论(0编辑  收藏  举报