JSP第二周作业

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

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
  <head>
    <title></title>
</head>
  <body>
  <h1>
  <%
 Date date = new Date();
 date.getHours();
   %>
  </h1>
<h2 style="font-family:宋体;fond-size:25;color:blue">
  <br>现在是北京时间:<%=date.getHours()%>:<%=date.getMinutes() %>:<%=date.getSeconds() %></br>
  <%
  if(date.getHours()>0&&date.getHours()<12){
  out.print("上午好");
  }else if(date.getHours()>12&&date.getHours()<17){
  out.print("下午好");
  }else if(date.getHours()>17&&date.getHours()<23){
  out.print("晚上好");
  }
   %>
  </h2>
  </body>
</html>

 

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

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

<html>
  <head>
    <title></title>
  </head>
  
  <body>
    
  <%! 

   public String panbie(int year){
   if(year%4==0&&year%100!=0||year%400==0){
       return "该年是闰年";
   }else{
   return "该年不是闰年";
   }
   }

    %>
    <h2 style="font-family:宋体;fond-size:25;color:blue">
    
     <%
      String y = panbie(2023);
      out.print(y);
      %> 
  </h2>
  </body>
</html>

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

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

<html>
<head>

</head>

<body>
    <%
        for (int i = 1; i <= 5; i++){
    %>
        <hr width ="<%=i*100 %>>">
        <%
        }
         %>
</body>
</html>

 

posted @ 2022-03-12 16:49  TS花间酒  阅读(8)  评论(0编辑  收藏  举报