Fork me on GitHub

JSP第二周作业

1.p39 实验2 显示当前时间,并输出上午(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+"/";
%>
<%!
//Java注释内容
public String tdate(){
Calendar c=Calendar.getInstance();
int hour=c.get(Calendar.HOUR);
String t = null;
if(hour>=0&&hour<=12){
t = "上午好";
}else if(hour>=13&&hour<=17){
t = "下午好";
}else if(hour>=18&&hour<=23){
t = "晚上好";
}
return t;
}

 %>
<!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>
    欢迎你<br>
    <%
    out.print(tdate());
    %>
  </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+"/";
%>
<%!
public String tdate(int year){

String t = null;
if(year%4==0&&year%100!=0||year%400==0){
t = "今年是闰年";
}else{
t = "今年不是闰年";
}
return t;
}

 %>
<!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>
  <!-- HTML注释内容 -->
    欢迎你<br>
    <%
    out.print("2022年"+tdate(2022));
    %>
  </body>
</html>

  

 

 

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

<%@ 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>
	<%--JSP注释内容 --%>
    <%
    for(int i = 100 ; i<=500;i+=100){
    %>
    <hr width = "<%=i%>">
    <%}
    %>
  </body>
</html>

  

 

 


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

posted @ 2022-03-09 11:13  Y6  阅读(38)  评论(0编辑  收藏  举报