第二周jsp作业

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

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%!public int continueSum(int start, int end) {
        int sum = 0;
        for (int i = start; i <= end; i++)
            sum = sum + i;
        return sum;
    }%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>My JSP 'index.jsp' starting page</title>

</head>

<body>
    <script type="text/javascript">
        var userTime = new Date();
        var hour = userTime.getHours();
        var minute = userTime.getMinutes();
        document.write("浏览器时间:"+hour + ":" + minute);
        
    </script>
    <%
        Date d = new Date();
        int hour = d.getHours();
        int minute = d.getMinutes();
out.print("服务器时间:"+hour + ":" + minute);
        if (hour >= 0 && hour <= 12) {
            out.print("上午好");
        } else if (hour >= 13 && hour <= 17) {
            out.print("下午好");
        } else {
            out.print("晚上好");
        }
    %>
</body>
</html>

 

 


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

<%@ 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>
<%! public void run(int year){

    if((year%4==0&&year%100!=0)||(year%400==0)){
        System.out.print(year+"是闰年");
      }
     else{
     System.out.print(year+"不是闰年");
     
        }
    } %>
    <% int year=2023;
        run(year);
     %>
</body>
</html>

 

 


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

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

<%@ 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>

         <%for(int i=1;i<=5;i++){ %>
         <hr width="<%=i*100%>">
         
       <% 
       } %>
    
</body>
</html>

 

 


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

第一题注释
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%!public int continueSum(int start, int end) {
        int sum = 0;
        for (int i = start; i <= end; i++)
            sum = sum + i;
        return sum;
    }%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>My JSP 'index.jsp' starting page</title>

</head>

<body>
    <script type="text/javascript">
        var userTime = new Date();
        var hour = userTime.getHours();
        var minute = userTime.getMinutes();
        document.write("浏览器时间:"+hour + ":" + minute);
        
    </script>
    
    <%
    /*
        Date d = new Date();
        int hour = d.getHours();
        int minute = d.getMinutes();
out.print("服务器时间:"+hour + ":" + minute);
        if (hour >= 0 && hour <= 12) {
            out.print("上午好");
        } else if (hour >= 13 && hour <= 17) {
            out.print("下午好");
        } else {
            out.print("晚上好");
        }
        */
    %>
    
</body>
</html>

第二题

<%@ 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>
<!-- 这个是HTML注释 -->
<body>
<%! public void run(int year){

    if((year%4==0&&year%100!=0)||(year%400==0)){
        System.out.print(year+"是闰年");
      }
     else{
     System.out.print(year+"不是闰年");
     
        }
    } %>
    <% int year=2023;
        run(year);
     %>
</body>
</html>

第三题

<%@ 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>


<%--  这个是jsp的注释 --%>
         <%for(int i=1;i<=5;i++){ %>
         <hr width="<%=i*100%>">
         
       <% 
       } %>
    
</body>
</html>

 

posted @ 2022-03-15 18:51  宋驰  阅读(28)  评论(0编辑  收藏  举报