JSP第二次作业

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

Java注释

 

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.text.SimpleDateFormat"%>
<%
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>
    
    <%
        /*获取日期、时间*/
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        int hour = date.getHours();
    %>
   
    <h2>
        <%
             /*对日期时间进行输出以及对时间判断*/
            out.print(sdf.format(date) + "</br>");
            if (hour > 0 && hour <= 12) {
                out.print("上午好");
            } else if (hour > 12 && hour <= 18) {
                out.print("下午好");
            } else {
                out.print("晚上好");
            }
            
        %>
    </h2>
  </body>
</html>

 

 

 

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

 

html注释

 

<%@ 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>
  <!-- 判断闰年声明方法 -->
      <%! 
       String Run(int year){
       if(year%4==0&&year%100!=0||year%400==0){
       return year+"是闰年";
       }else{
       return year+"不是闰年";
       }
       }
      %>
      <% String y=Run(2023);
         out.print(y);
      %>
      
  </body>
</html>

 

  

 

 

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

<hr width="<%=i%>"

jsp注释

 

<%@ 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 x = 100;
	%>
	<%
		for (int y = 1; y <= 5; y++) {
	%>
	<hr width="<%=x * y%>">
	<%
		}
	%>
</body>
</html>

 

 

posted @ 2022-03-12 14:22  计算机1901万家乐  阅读(11)  评论(0编辑  收藏  举报