贾云鹏

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></title>
    

  </head>
  
  <body>
    <%
        Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH) + 1;
        int date = c.get(Calendar.DATE);
        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);
        int second = c.get(Calendar.SECOND);
        String x = "";   
        if (hour >= 0 && hour <= 12) { 
            x = "上午好!";
        } else if (hour >= 13 && hour <= 17) {
            x = "下午好!";
        } else if (hour >= 18 && hour <= 23) {
            x = "晚上好!";
        }
    %>
    <p>
        当前时间为:<%=year%>/<%=month%>/<%=date%>
        <%=hour%>:<%=minute%>:<%=second%><br>
    </p>
    <p><%=x%></p> <br>
  </body>
</html>

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

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%!int i = 0;
    int j = 0;%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<%!
    boolean isRun(int year){
    if(year%4==0&&year%100!=0||year%400==0){
        return true; 
    }
    return false;
}  %>
<html>
  <head> 
  <!-- HTML注释 -->
    <title>My JSP 'index.jsp' starting page</title>
  </head>
  <body>
  <%
  boolean f=isRun(2023);
  out.print(f);
   %>
  </body>
</html>

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

<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<h2>

 

</h2>
</body>
<%--jsp注释--%>
<%
    for (int i = 100; i <= 500; i = i+100) {
%>
<hr width="<%=i%>" color="red">
<%
    }
%>
</html>

 

 

posted on 2022-03-13 09:08  贾云鹏  阅读(23)  评论(0编辑  收藏  举报

导航