jsp第二次作业

1.p39 实验2 显示当前时间,并输出上午(0-12)好,下午好(13-17),晚上好(18-23)
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %><%--
Created by IntelliJ IDEA.
User: bad boy
Date: 2022/3/11
Time: 21:28
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<body>
当前时间为:
<%
Date d = new Date();//获取系统时间
int h=d.getHours();
int m=d.getMinutes();
int a=d.getSeconds();
out.print("当前时间:"+h+":"+m+":"+a) ;
if(h>=0&&h<=12){//判断时间范围并输出相应的问候语
out.print("上午好");
}else if(h>=13&&h<=17){
out.print("下午好");
}else{
out.print("晚上好");
}
%>
</body>

</html>

2. 使用声明方法,在页面调用该方法,判断2023是不是闰年
<%--
Created by IntelliJ IDEA.
User: bad boy
Date: 2022/3/11
Time: 21:54
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%!
int i = 0;
int j = 0;%>
<html>
<%!
boolean isRun(int year){
if(year%4==0&&year%100!=0||year%400==0){
return true;
}
return false;
} %>
<html>
<head>

<title>
My JSP 'index.jsp' starting page
</title>
</head>
<body>
<%
boolean f=isRun(2023);
out.print(f);
%>
</body>
</html>

3.表达式+程序段 循环输出5条hr,长度分别为100px-500px
<hr width="<%=i%>"
<%--
Created by IntelliJ IDEA.
User: bad boy
Date: 2022/3/11
Time: 21:54
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<head>
<title>Mddddd</title>
</head>

<body>
<%
for (int i = 1; i <= 5; i++) {
%>
<hr width="<%=i * 100%>px">
<%
}
%>
</body>



 

posted @ 2022-03-11 22:03  高杨翔  阅读(39)  评论(0编辑  收藏  举报