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> <% //java注释 Calendar y=Calendar.getInstance(); int year=y.get(Calendar.YEAR); int month=y.get(Calendar.MONTH)+1; int day=y.get(Calendar.DAY_OF_MONTH); int hour=y.get(Calendar.HOUR_OF_DAY); int minute=y.get(Calendar.MINUTE); if(hour<12){ out.print("早上好~");} else if(hour==12){ out.print("中午好~"); } else{ out.print("下午好~");} %> <h2> 用户在<%=year %>/<%=month %>/<%=day %> <%=hour %>:<%=minute %>使用浏览器 </h2> </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> <title>My JSP 'MyJsp.jsp' starting page</title> </head> <!--html注释 --> <body> <%!String zuoye(int year) { if(year%4==0&&year%100!=0||year%400==0){ return year + "闰年"; }else{return year + "平年";} }%> <% String yearr=zuoye(2021); out.print(yearr); %> </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> <title>My JSP 'MyJsp1.jsp' starting page</title> </head> <%--jsp注释 --%> <body> <%for(int i=1;i<5;i++){ %> <hr width="<%=i*100%>px"> <% } %> </body> </html>
4.在第一题上加Java注释,第二题加html注释,第三题加jsp注释