JSP第二次作业
1.p39 实验2 显示当前时间,并输出上午(0-12)好,下午好(13-17),晚上好(18-23)
<html> <head> <title>JSP第二次作业</title> </head> <body> <% //Java注释 LocalDate date = LocalDate.now(); LocalTime time = LocalTime.now(); %> <h1>欢迎光临, <% if (time.getHour() <= 12 && time.getHour() >= 0) { out.print("上午好!"); } else if (time.getHour() >= 13 && time.getHour() <= 17) { out.print("下午好!"); } else if (time.getHour() >= 18 && time.getHour() <= 23) { out.print("晚上好!"); } %> </h1> <h2> 用户在<%=date.getYear()%>年<%=date.getMonthValue()%>月<%=date.getDayOfMonth()%>日<%=time.getHour()%>:<%=time.getMinute()%> :<%=time.getSecond()%>访问了该网页! </h2>
2. 使用声明方法,在页面调用该方法,判断2023是不是闰年
<h1> <!-- HTML注释--> <%! public static boolean judgeYear(int year) { if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { return true; } else { return false; } } %> <% boolean Y=judgeYear(2023); if (Y){ out.println("该年是闰年!"); }else { out.println("该年不是闰年!"); } %> </h1>
3.表达式+程序段 循环输出5条hr,长度分别为100px-500px
<body> <%--JSP注释--%> <% for (int i = 1; i <= 5; i++) { %> <hr width="<%=i*100%>px" color="blue"> <% } %> </body>