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> <head> <title>My JSP 'index.jsp' starting page</title> </head> <body> <% Date d=new Date(); int h=d.getHours(); int m=d.getMinutes(); int s=d.getSeconds(); out.print("当前时间:"+h+":"+m+":"+s+"<br>"); if(h>=0&&h<=12){ out.print("早上好"); }else if(h>=13&&h<=17){ out.print("下午好"); }else if(h>=18&&h<=23){ out.print("晚上好"); } %> </body> </html>
2.使用声明方法,在页面调用该方法,判断2023是不是闰年
<body> <%! int Year(int y){ return y;}%> <!--HTML注释--> <% int y=2023; if(y%4==0&&y%100!=0||y%400==0){ out.println(y+"是闰年");} else{out.println(y+"不是闰年");}%> <br> </body>
3.表达式+程序段 循环输出5条hr,长度分别为100px-500px
<hr width="<%=i%>"
<body> <%--jsp注释 --%> <% for (int i = 1; i <= 5; i++) { %> <hr width="<%=i * 100%>px" color="green"> <% } %> </body>