jsp2
1.p39 实验2 显示当前时间,并输出上午(0-12)好,下午好(13-17),晚上好(18-23)
1 <%@page import="com.sun.xml.internal.txw2.Document"%> 2 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 4 <html> 5 <head> 6 <title>My JSP 'index.jsp' starting page</title> 7 </head> 8 <body> 9 10 <% 11 //java注释 12 Date d=new Date(); 13 int hour=d.getHours(); //获取小时 14 int minute=d.getMinutes();//获取分钟 15 int second=d.getSeconds();//获取秒 16 out.print("当前时间:"+hour+":"+minute+":"+second+"<br><br>"); 17 if(hour>=0&&hour<=12){ 18 out.print("早上好"); 19 }else if(hour>=13&&hour<=17){ 20 out.print("下午好"); 21 }else if(hour>=18&&hour<=23){ 22 out.print("晚上好"); 23 } 24 %> 25 </body> 26 </html>
2. 使用声明方法,在页面调用该方法,判断2023是不是闰年
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 <%!int i = 0; 3 int j = 0;%> 4 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 5 <html> 6 <%! 7 boolean isRun(int year){ 8 if(year%4==0&&year%100!=0||year%400==0){ 9 return true; 10 } 11 return false; 12 } %> 13 <html> 14 <head> 15 <!-- HTML注释 --> 16 <title>My JSP 'index.jsp' starting page</title> 17 </head> 18 <body> 19 <% 20 boolean f=isRun(2023); 21 out.print(f); 22 %> 23 </body> 24 </html>
3.表达式+程序段 循环输出5条hr,长度分别为100px-500px
<hr width="<%=i%>"
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 %> 6 7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 8 <html> 9 <head> 10 <base href="<%=basePath%>"> 11 12 <title>My JSP 'two.jsp' starting page</title> 13 14 <meta http-equiv="pragma" content="no-cache"> 15 <meta http-equiv="cache-control" content="no-cache"> 16 <meta http-equiv="expires" content="0"> 17 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 18 <meta http-equiv="description" content="This is my page"> 19 <!-- 20 <link rel="stylesheet" type="text/css" href="styles.css"> 21 --> 22 23 </head> 24 25 <body> 26 3.表达式+程序段 循环输出5条hr,长度分别为100px-500px <br> 27 <%--jsp注释 --%> 28 <% 29 for(int i=1;i<=5;i++){ %> 30 <hr width="<%=i*50%>px"> 31 <% }%> 32 </body> 33 </html>