JSP第二次作业

1.显示当前时间,并输出上午(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>
  </head>
  
  <body>
  <%
    Date d = new Date();
    out.println(d.getHours());             //显示当前时间
    if(d.getHours()>=0 && d.getHours()<=12)//判断时间
    out.print("下午好");
    else if(d.getHours()>=13&&d.getHours()<=17)
    out.print("中午好");
    else
    out.print("晚上好");
   %>
  </body>
</html>

2.使用声明方法,在页面调用该方法,判断2023是不是闰年

<%@ 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>
 
    <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>
 
          <%! public String year(int year){
 
                 String result = "平年";
 
                 if((year/4 == 0 && year/100!=0)&&year/400==0){
 
                        result = "闰年";
 
                 }
 
                 return result;
 
          }
 
       %>            
 
              
 
       <%
 
              String year = year(2023);
 
              out.print(year);
 
       %>     
 
   
 
  </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>
 
</head>
 
<body>
    <%
    for(int x=100;x<600;x+=100){    //判断
     %>
    <hr width="<%=x%>" px color=red>
    <%
     }
      %>
</body>
</html>

 

posted @ 2022-03-13 22:44  五谷鸡爪🥳  阅读(10)  评论(0编辑  收藏  举报