JSP第二周作业
1.p39 实验2 显示当前时间,并输出上午(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> <title>My JSP 'index.jsp' starting page</title> </head> <body> <% Date d = new Date(); //获取小时 out.println(d.getHours());//输出得到的小时<br> %> <% if(d.getHours()>=0 && d.getHours()<=12){ %> <h2>上午好</h2> <% } else if(d.getHours()>=13&&d.getHours()<=17){ %> <h2>下午好</h2> <% }else{ %> <h2>晚上好</h2> <%} %> <br> </body>
2. 使用声明方法,在页面调用该方法,判断2023是不是闰年
<
body
>
<!-- 定义方法judy -->
<%!int judy(int year){
if (year%4==0&year%400==0){
return 0;
}
else{
return 1;
}}
%>
<%
int year=2023;
int i=judy(year);
if (i==0){
out.println("是闰年");
}
else{
out.println("不是闰年");
}
%>
</
body
>
3.表达式+程序段 循环输出5条hr,长度分别为100px-500px
<hr width="<%=i%>"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% for(int i=1;i<=5;i++){ %> <hr width="<%=i*100%>px"><%--jsp注释 --%> <% }%> </body> </html>
4.在第一题上加Java注释,第二题加html注释,第三题加jsp注释