jsp第二周作业

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

<%@ 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>
     1.p39   实验2 显示当前时间,并输出上午(0-12)好,下午好(13-17),晚上好(18-23)<br>
    
    
   <%
    //java注释
    Date date=new Date();
    int hour=date.getHours(); //获取小时
    int minute=date.getMinutes();//获取分钟
    int second=date.getSeconds();//获取秒
    out.print("当前时间是:"+hour+":"+minute+":"+second+"<br>");
    if(hour>=0&&hour<=12){
    out.print("Goodmoring");
    }else if(hour>=13&&hour<=17){
    out.print("G");
    }else if(hour>=18&&hour<=23){
    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 'three.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>
    2. 使用声明方法,在页面调用该方法,判断2023是不是闰年
    <br>
    <%!boolean isRun(int year) {
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
            return true;
        }
        return false;
    }%>
    <%
        boolean b = isRun(2023);
        out.print("2023"+b);
    %>
  </body>
</html>

 

 

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

<%@ 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 'two.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>
     3.表达式+程序段   循环输出5条hr,长度分别为100px-500px <br>
     <%--jsp注释 --%>
  <%
  for(int i=1;i<=5;i++){ %>
  <hr width="<%=i*50%>px">
  <% }%>
  </body>
</html>

 

posted @ 2022-03-11 19:35  聂芳芳  阅读(32)  评论(0)    收藏  举报