黑马prince

导航

JSP第二次作业

1.p39 实验2 显示当前时间,并输出上午(0-12)好,下午好(13-17),晚上好(18-23)<br><%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
 
</head>
 
<body>
    <%
        Calendar c = Calendar.getInstance();
        int hour = c.get(Calendar.HOUR);
        int minute = c.get(Calendar.MINUTE);
        int second = c.get(Calendar.SECOND);
    %><!-- 获取电脑时间 -->
    <h1>
        用户在<%=hour%>:<%=minute%>:<%=second %>访问了网页
    </h1>
    <%
        //判断
        if (hour >= 0 && hour <= 12) {
            out.print("上午好");
        } else if (hour >= 13 && hour <= 17) {
            out.print("下午好");
        } else if (hour >= 18 && hour <= 23) {
            out.print("晚上好");
        }
    %>
</html>

 

 

2. 使用声明方法,在页面调用该方法,判断2023是不是闰年
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
 
</head>
 
<body>
    <%!String sal(int x, String m, String n) {
        if (x % 4 == 0 && x % 100 != 0 || x % 400 == 0) {
            return m;
        }
        return n;
    }%><!-- 定义声明方法 -->
    <%
        String y = sal(2023, "闰年", "平年");
        out.print(y);
    %>
</body>
</html>

 

 

3.表达式+程序段 循环输出5条hr,长度分别为100px-500px
<hr width="<%=i%>"
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
 
</head>
 
<body>
    <%
    for(int x=100;x<600;x+=100){    //判断
     %>
    <hr width="<%=x%>" px color=red>
    <%
     }
      %>
</body>
</html>

 

posted on 2022-03-20 12:04  HumbleSwag  阅读(8)  评论(0编辑  收藏  举报