第二周作业


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

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'index.jsp' starting page</title>
    
  </head>
  
  <body>
 hgfddKJHSGSDJGFHSDG<br>
 <%
 Calendar c=Calendar.getInstance();
 int year=c.get(Calendar.YEAR);
  int month=c.get(Calendar.MONTH)+1;
   int date=c.get(Calendar.DATE);
    int hour=c.get(Calendar.HOUR);
     int minute=c.get(Calendar.MINUTE);
      int second=c.get(Calendar.SECOND);
       String str="";
       if(hour>=0&&hour<=12){str="上午好";}
       else  if(hour>=13&&hour<=17){str="下午好";}
       else  if(hour>=18&&hour<=23){str="晚上好";}
  %>
  现在日期为<%=year %>-<%=month %>-<%=date %> <br>
  现在时间为 <%=hour %>:<%=minute %>:<%=second %><br>
  <%=str %>!
  </body>
</html>

 

 

 


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

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%!
public static boolean year(int y){
if(y%4==0&&y%100!=0||y%400==0){return true;}
else {return false;}
}
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  </head>
  <body>
 <%
boolean n=year(2023);
 out.print(n);
  %>
 
  </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 i=1;i<=5;i++){ %>
  <hr width="<%=i*100%>px">
  <% }%>
 
  </body>
</html>

 

 

 


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

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'index.jsp' starting page</title>
    
  </head>
  
  <body>
 hgfddKJHSGSDJGFHSDG<br>
 <%
 //java注释
 Calendar c=Calendar.getInstance();
 int year=c.get(Calendar.YEAR);
  int month=c.get(Calendar.MONTH)+1;
   int date=c.get(Calendar.DATE);
    int hour=c.get(Calendar.HOUR);
     int minute=c.get(Calendar.MINUTE);
      int second=c.get(Calendar.SECOND);
       String str="";
       if(hour>=0&&hour<=12){str="上午好";}
       else  if(hour>=13&&hour<=17){str="下午好";}
       else  if(hour>=18&&hour<=23){str="晚上好";}
  %>
  现在日期为<%=year %>-<%=month %>-<%=date %> <br>
  现在时间为 <%=hour %>:<%=minute %>:<%=second %><br>
  <%=str %>!
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%!
public static boolean year(int y){
if(y%4==0&&y%100!=0||y%400==0){return true;}
else {return false;}
}
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  </head>
  <body>
  <!-- html注释 -->
 <%
boolean n=year(2023);
 out.print(n);
  %>
 
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  </head>
  <body>
  <%--jsp注释 --%>
<%
  for(int i=1;i<=5;i++){ %>
  <hr width="<%=i*100%>px">
  <% }%>
 
  </body>
</html>

 

 

posted @ 2022-03-12 15:30  崔明月  阅读(12)  评论(0编辑  收藏  举报