第二周jsp作业

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

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="java.util.*"%>
<%@page import="java.text.SimpleDateFormat"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>显示当前时间</title>
</head>
<body>
    <h1>
        显示访问网页的日期、时间<br>(服务器端的日期、时间)
    </h1>
    <%
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        int hour = date.getHours();
    %>
    <h2>
        <%
            
            out.print(sdf.format(date) + "</br>");
            if (hour > 0 && hour <= 12) {
                out.print("上午好");
            } else if (hour > 12 && hour <= 18) {
                out.print("下午好");
            } else {
                out.print("晚上好");
            }
            
        %>
    </h2>
</body>
</html>

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

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>判断是否为闰年</title>
</head>
<body>
<!-- 2. 使用声明方法,在页面调用该方法,判断2023是不是闰年  -->
    <%!boolean x(int year) {
        if (year % 4 == 0 && year % 100 != 100 || year % 400 == 0) {
            return true;
        } else {
            return false;
        }
    }%>
    <%
        if (x(2023)) {
            out.print("是闰年");
        } else {
            out.print("不是闰年");
        }
    %>
</body>
</html>

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

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>循环输出5条hr</title>
</head>
<body>
<%--表达式+程序段 循环输出5条hr,长度分别为100px-500px --%>
    <%
        for (int i = 100; i <= 500; i+=100) {    %>
    <hr width="<%=i%>">
    <% } %>
</body>
</html>

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

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="java.util.*"%>
<%@page import="java.text.SimpleDateFormat"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>显示当前时间</title>
</head>
<body>
    <h1>
        显示访问网页的日期、时间<br>(服务器端的日期、时间)
    </h1>
    <%
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        int hour = date.getHours();
    %>
    <h2>
        <%
            /*
            out.print(sdf.format(date) + "</br>");
            if (hour > 0 && hour <= 12) {
                out.print("上午好");
            } else if (hour > 12 && hour <= 18) {
                out.print("下午好");
            } else {
                out.print("晚上好");
            }
            */
        %>
    </h2>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>判断是否为闰年</title>
</head>
<body>
<!-- 2. 使用声明方法,在页面调用该方法,判断2023是不是闰年  -->
    <%!boolean x(int year) {
        if (year % 4 == 0 && year % 100 != 100 || year % 400 == 0) {
            return true;
        } else {
            return false;
        }
    }%>
    <%
        if (x(2023)) {
            out.print("是闰年");
        } else {
            out.print("不是闰年");
        }
    %>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>循环输出5条hr</title>
</head>
<body>
<%--表达式+程序段 循环输出5条hr,长度分别为100px-500px --%>
    <%
        for (int i = 100; i <= 500; i+=100) {    %>
    <hr width="<%=i%>">
    <% } %>
</body>
</html>

 

posted @ 2022-03-10 15:35  计算机1901金皓楠  阅读(39)  评论(0编辑  收藏  举报