第二周作业
<%@page import="com.sun.xml.internal.txw2.Document"%> <%@ 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> <% //java注释 Date d=new Date(); int hour=d.getHours(); //获取小时 int minute=d.getMinutes();//获取分钟 int second=d.getSeconds();//获取秒 out.print("当前时间:"+hour+":"+minute+":"+second+"<br><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是不是闰年
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <!--HTML注释语句--> <body> <h1>判断闰年</h1> <%! String panduan(int a){ if((a%4==0&&a%100!=0)||a%400==0){ return "闰年"; }else{ return "平年"; } } %> <% int a=2023; out.print("2023为"+panduan(a)); %> </body> </html>
3.表达式+程序段 循环输出5条hr,长度分别为100px-500px
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 3 <html> 4 <head> 5 <title>My JSP 'index.jsp' starting page</title> 6 </head> 7 8 <body> 9 <%--jsp注释 --%> 10 <% 11 for (int i = 1; i <= 5; i++) { 12 %> 13 <hr width="<%=i * 100%>px" size="<%=i%>" color="blue"> 14 <% 15 } 16 %> 17 <br /> 18 19 20 </body> 21 </html>