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> <title>显示时间</title> </head> <body> <% //java注释 Date d=new Date(); int hour=d.getHours();//获取小时 int minute=d.getMinutes(); int second=d.getSeconds(); if(hour>=0&&hour<=12){ out.print("当前时间为"+hour+":"+minute+":"+second+"上午好"); }else if(hour>12&&hour<=17){ out.print("当前时间为"+hour+":"+minute+":"+second+"下午好"); }else{ out.print("当前时间为"+hour+":"+minute+":"+second+"晚上好"); } %> </body> </html>


 

 
2. 使用声明方法,在页面调用该方法,判断2023是不是闰年
闰年:能被4整除但不能被100整除或者能被400整除
<%@ 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>
  <title>判断是否为闰年</title>
  </head>
  <body>
<%!
 public String getYear(int year){
 String z=null;
  if(year%4==0&&year%100!=0||year%400==0){
    z="是闰年";
   }else{
    z="不是闰年";
    }
    return z;
    }%>
    <!-- html注释 -->
 <%
 out.print("2023年"+getYear(2023));
  %>
  </body>
</html>

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

<%@ 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>
  <title>长度</title>
  </head>
  <body>
  <%--jsp注释 --%><%
for(int i=1;i<=5;i++){%>
<hr width="<%=i*100%>px">
<%} %>
  </body>
</html>

 

posted @ 2022-03-19 21:57  XLKL  阅读(9)  评论(0编辑  收藏  举报