JSP第二周作业

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

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
    <%
        Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);//获取年份
        int month = c.get(Calendar.MONTH);//获取月份
        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);//获取秒
        out.print("当前时间:"+year+":"+month+":"+date+":"+hour+":"+minute+":"+second+"<br>");
        if(hour>=0&&hour<=12){//选择语句输出结果
        out.print("上午好!");
        }else if(hour>=13&&hour<=17){
        out.print("下午好!");
        }else if(hour>=18&&hour<=23){
        out.print("晚上好!");
        }
    %>
</body>
</html>

  

 

 

2. 使用声明方法,在页面调用该方法,判断2023是不是闰年
闰年:能被4整除但不能被100整除或者能被400整除

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'second.jsp' starting page</title>
<%!boolean x(int year) {
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
            return true;
        } else {
            return false;
        }
    }%>
</head>
<!-- HTML注释 -->
<body>
    <%
        boolean y = x(2023);
        out.print(y);
    %>
</body>
</html>

  

 

 

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

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'third.jsp' starting page</title>
</head>
<%--jsp注释 --%>
<body>
    <%
        for (int i = 1; i <= 5; i++) {
    %>
    <hr width="<%=i * 100%>px">
    <%
        }
    %>
</body>
</html>

  

 

posted @ 2022-03-13 12:05  蓝桉亞  阅读(6)  评论(0编辑  收藏  举报