色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

JSP實時顯示當前系統時間的四種方式示例解析

瀏覽:225日期:2022-06-08 09:37:05

JSP顯示當前系統時間的四種方式:

第一種java內置時間類實例化對象:

<%@ 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%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
  
  <title>My JSP "time4.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" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
	-->
 
 </head>
 
 <body>
  <%
  java.text.SimpleDateFormat simpleDateFormat = new java.text.SimpleDateFormat( 
   "yyyy-MM-dd HH:mm:ss"); 
  java.util.Date currentTime = new java.util.Date(); 
  String time = simpleDateFormat.format(currentTime).toString();
  out.println("當前時間為:"+time);
   %>
   
 </body>
</html>

第二種方式使用JSP內置USEBEAN實例化時間類:

<%@ 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%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
  
  <title>顯示系統時間方法一:</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" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
	-->
 
 </head>
 
 <body>
  <jsp:useBean id="time"/>
  	現在時間:<%=time%>
 </body>
</html>

第三種方式使用JSP USEBEAN type與beanName配對使用:

<%@ 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%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
  
  <title>My JSP "time2-useBean-type-beanName.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" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
	-->
 
 </head>
 
 <body>
   <jsp:useBean id="time" type="java.io.Serializable" beanName="java.util.Date"/>
  	現在時間:<%=time%>
 </body>
</html>

第四種方式使用JSP setproperty設置屬性:

<%@ 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%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
  
  <title>My JSP "time3-setproperty.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" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
	-->
 
 </head>
 
 <body>
  jsp:setproperty 實例<hr>
  <jsp:useBean id="time">
  	<jsp:setProperty name="time" property="hours" param="hh"/>
  	<jsp:setProperty name="time" property="minutes" param="mm"/>
  	<jsp:setProperty name="time" property="seconds" param="ss"/>
  </jsp:useBean>
  <br>
  設置屬性后的時間:${time} }
  <br>
  
 </body>
</html>

所有代碼均能直接復制到MYECLIPSE2010

到此這篇關于JSP實時顯示當前系統時間的四種方式示例解析的文章就介紹到這了,更多相關JSP實時顯示當前系統時間內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!

標簽: JSP
主站蜘蛛池模板: 国产三级精品91三级在专区 | 国产毛片不卡 | 99视频精品全部 在线 | 国产成人精品免费视频大全五级 | 2018久久久国产精品 | 国内自拍在线观看 | 欧美顶级毛片在线播放小说 | 超91在线| 欧美成人免费观看久久 | 亚洲羞羞裸色私人影院 | 波多野结衣一区二区三区高清在线 | 久草资源免费 | 国产日韩精品在线 | a级成人高清毛片 | 欧美xxxxb| 久草最新网址 | 久久精品99精品免费观看 | 在线观看免费精品国产 | 一级毛片免费观看视频 | 欧美特级另类xxx | 亚洲高清在线观看视频 | 久久精品国产大片免费观看 | 韩国porno xxxx | 日韩欧美一区二区不卡看片 | 老师张开腿让我爽了一夜视频 | 看片亚洲 | 国产美女一区精品福利视频 | 亚洲人成在线免费观看 | 2022免费国产精品福利在线 | 精品国产91久久久久 | 日本妞xxxxxxxxx69 | 性欧美成人依依影院 | 黄色网点| 亚洲综合免费 | 亚洲欧美日韩另类精品一区二区三区 | 欧美视频一区 | 国产乱肥老妇精品视频 | 国产一区中文字幕在线观看 | 国产毛片基地 | 日韩国产欧美一区二区三区 | 免费看成人毛片日本久久 |