jsp第二次作业
1.显示当前时间,并输出上午(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> </head> <body> <% Date d = new Date(); out.println(d.getHours()); //显示当前时间 if(d.getHours()>=0 && d.getHours()<=12)//判断时间 out.print("下午好"); else if(d.getHours()>=13&&d.getHours()<=17) out.print("中午好"); else out.print("晚上好"); %> </body> </html>
2.使用声明方法,在页面调用该方法,判断2023是不是闰年
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%! boolean b(int x){ return x%4==0||x%100!=0&&x%400==0; } %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body> 判断2023是不是闰年:<%=b(2023) %><!-- 调用并输出结果 --> </body> </html>
3.表达式+程序段 循环输出5条hr,长度分别为100px-500px
<%@ 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> </head> <body> <% for(int x=1;x<=5;x++){ %> <%--循环5次输出直线 --%> <hr width="<%=x*100%>px"> <br> <%} %> </body> </html>