<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.util.*"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body><% Date d=new Date(); %>
<% int hours=d.getHours(); %>
<% if(hours>5 && hours<=8){ %>
<script> alert("早上好"); </script>
<% }else if(hours<12){%>
<script>alert("上午好");</script>
<% }else if(hours<18){%>
<script>alert("早上好");</script>
<% }else if(hours<21){%>
<script>alert("晚上好");</script>
<% }else if(hours<23){%>
<script>alert("祝你晚安!");</script>
<% }else{%>
<script>alert("网虫,该休息了,明天还有课呢!");</script>
<% }%>
</body>
</html>
运行结果如下