# 第二次作业

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

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%!public int continueSum(int start, int end) {
int sum = 0;
for (int i = start; i <= end; i++)
sum = sum + i;
return sum;
}%>

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

<title>My JSP 'index.jsp' starting page</title>

<body>
<script type="text/javascript">
var userTime = new Date();
var hour = userTime.getHours();
var minute = userTime.getMinutes();
document.write("浏览器时间:"+hour + ":" + minute);

</script>
<%
Date d = new Date();
int hour = d.getHours();
int minute = d.getMinutes();
out.print("服务器时间:"+hour + ":" + minute);
if (hour >= 0 && hour <= 12) {
out.print("上午好");
} else if (hour >= 13 && hour <= 17) {
out.print("下午好");
} else {
out.print("晚上好");
}
%>
</body>
</html>

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

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%!     String panduan(int a){         if((a%4==0&&a%100!=0)||a%400==0){             return "闰年";         }else{             return "平年";         }     }      %>      <%      int a=2023;      out.print("2023为"+panduan(a));       %>

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 @ 2022-03-13 18:26  郭蕴杰  阅读(8)  评论(0编辑  收藏  举报