jsp第二周作业

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

 

<%@page import="sun.util.resources.LocaleData"%>
<%@ 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>
           当前时间是
    <%
        Calendar c = Calendar.getInstance();
        out.println(c.get(Calendar.YEAR)+"");
        out.println(c.get(Calendar.MONTH)+1+"");
        out.println(c.get(Calendar.DAY_OF_MONTH)+"");
        out.println(c.get(Calendar.HOUR)+"");
        out.println(c.get(Calendar.MINUTE)+"");
        out.println(c.get(Calendar.SECOND)+"");
        if(Calendar.HOUR<12){
            out.println("上午好");
        }else if(Calendar.HOUR>13&&Calendar.HOUR<17){
            out.println("中午好");
            
        }else{
            out.println("下午好");
        }
        
     %>
  </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 'MyJsp.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>
    
    <%!
        int show(int year){
            if(year%4==0&&year%400!=0||year%400==0){
                return 1;
            }else{
            return 0;
            }
        }
     %>
     <%
         if(show(2023)==1){
             out.println("是闰年");
         }else{
             out.println("不是润年");
         }
      %>
  </body>
</html>

 

 

 

3.表达式+程序段   循环输出5hr,长度分别为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 'MyJsp1.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 i=100;i<600;i=i+100){ %>
           <hr width="<%=i%>">
       <%} %>
  </body>
</html>

 

 

 

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

 

 

 

posted @ 2022-03-14 17:40  王玉宁325  阅读(22)  评论(0编辑  收藏  举报