JSP第二周

1.p39 实验2 显示当前时间,并输出上午(0-12)好,下午好(13-17),晚上好(18-23)
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<%! public void judeYear (int year){if(year%400==0||year%4==0&year%100!=0){
  System.out.printf("润");
}else{
System.out.printf("bu润");}
}%>
  <head>
    <title>My JSP 'index.jsp' starting page</title>
  </head>
  
  <%
        Date d = new Date();
        int x=d.getHours();
        int y=d.getMinutes();
        int z=d.getSeconds();
            out.print("当前时间:"+x+":"+y+":"+z+"<br>");
        if (x >= 0 && x <= 12) {
            out.print("上午好!");
        } else if (x >= 13 && x <= 17) {
            out.print("中午好!");
        } else if (x >= 18 && x <= 23) {
            out.print("晚上好!");
           
        }
        %>
</body>
    
</html>

 

 

2. 使用声明方法,在页面调用该方法,判断2023是不是闰年
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<%! public void judeYear (int year){if(year%400==0||year%4==0&year%100!=0){
  System.out.printf("润");
}else{
System.out.printf("bu润");}
}%>
  <head>
    <title>My JSP 'index.jsp' starting page</title>
  </head>
  
  <body>
    <br>
    <%judeYear((2023)); %>
  </body>
</html>


3.表达式+程序段 循环输出5条hr,长度分别为100px-500px
<hr width="<%=i%>"
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'index.jsp' starting page</title>
  </head>
  
  <body>
    <br>
    <% for(int i=1;i<=5;i++) {%>
    <hr width="<%=i*100 %>">
    <%} %>
  </body>
</html>

4.在第一题上加Java注释,第二题加html注释,第三题加jsp注释
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<%! public void judeYear (int year){if(year%400==0||year%4==0&year%100!=0){
  System.out.printf("润");
}else{
System.out.printf("bu润");}
}
/* 程序员专属 */%>
  <head>
    <title>My JSP 'index.jsp' starting page</title>
  </head>
  <--! 用户可见 -->
  <%
        Date d = new Date();
        int x=d.getHours();
        int y=d.getMinutes();
        int z=d.getSeconds();
            out.print("当前时间:"+x+":"+y+":"+z+"<br>");
        if (x >= 0 && x <= 12) {
            out.print("上午好!");
        } else if (x >= 13 && x <= 17) {
            out.print("中午好!");
        } else if (x >= 18 && x <= 23) {
            out.print("晚上好!");
           
        }
        %>
</body>
    
</html>

 

posted @ 2022-03-12 12:11  计算机1903孙铭泽  阅读(12)  评论(0编辑  收藏  举报