Jsp第二次作业

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

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
 
    Calendar c=Calendar.getInstance();
    int hour=c.get(Calendar.HOUR);
   System.out.println(hour);
   
     %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  
    
    <title>显示当前日期</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>
  <br>
    <%
    if(hour>=0&&hour<=12)
   {out.print("上午好"+" "+hour+"");
   }else if(hour>=13&&hour<=17)
   {out.print("中午好"+" "+  hour+"");
   }else 
   {out.print("下午好"+" "+  hour+"");
   }
  
     %>
  </body>
</html>


2. 使用声明方法,在页面调用该方法,判断2023是不是闰年
闰年:能被4整除但不能被100整除或者能被400整除

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
 

     %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  
    
    <title>显示当前日期</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>
  <br>
    <%
    int year=2023;
    if(year%4==0&&year%100!=0||year%400==0)
   {out.print("闰年");
   }else 
   {out.print("平年");
   }
  
     %>
  </body>
</html>

 

 



3.表达式+程序段   循环输出5条<hr>,长度分别为100px-500px
<hr width="<%=i%>"

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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>
  <%
    for(int x=100;x<600;x+=100){   
     %>
    <hr width="<%=x%>" >
    <%
     }
      %>  </body>
</html>

 

 



4.在第一题上加Java注释,第二题加html注释,第三题加jsp注释


posted @ 2022-03-15 09:13  计算机1904谢家俊  阅读(31)  评论(0编辑  收藏  举报