1.实验2 显示当前时间,并输出上午(0-12)好,下午好(13-17),晚上好(18-23)。

<!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>
     <%Date h=new Date();
       int hour=h.getHours();
       int minute=h.getHours();//java注释
       int second=h.getSeconds();
        out.print("当前时间:"+hour+":"+minute+":"+second+"");
        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><!-- 我是一个HTML注释~~~~ -->
</head>
<body>
<%!boolean s(int year) {
if (year%4==0&&year%100!=0||year%400==0){
return true;
} else {
return false;
}
}%>
<%
boolean year=s(2023);
out.print(year);
%>
</body>
</html>

 

 

 

3.表达式+程序段 循环输出5条hr,长度分别为100px-500px

<!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>
      <%--jsp的注释呀~~~~~ --%>
  <%
  for(int a=1;a<=5;a++){ %>
  <h2><hr width="<%=a*100%>px" ></h2>
  <% }%>
  </body>
</html>

4.依次写注释

 

posted on 2022-03-09 21:52  郝梦瑶  阅读(40)  评论(0编辑  收藏  举报