主頁 > 知識庫 > JSP實時顯示當前系統(tǒng)時間的四種方式示例解析

JSP實時顯示當前系統(tǒng)時間的四種方式示例解析

熱門標簽:南通通訊外呼系統(tǒng)產(chǎn)品介紹 海外圖書館地圖標注點 電話機器人需要使用網(wǎng)絡(luò)嗎 外呼系統(tǒng)使用方法 電銷機器人免培訓 如何看懂地圖標注點 給地圖標注得傭金 自繪地圖標注數(shù)據(jù) 潤滑油銷售電銷機器人

JSP顯示當前系統(tǒng)時間的四種方式:

第一種java內(nè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%>" 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內(nèi)置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>顯示系統(tǒng)時間方法一:/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" class="java.util.Date"/>
  	現(xiàn)在時間:%=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"/>
  	現(xiàn)在時間:%=time%>
 /body>
/html>

第四種方式使用JSP setproperty設(shè)置屬性:

%@ 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" class="java.util.Date">
  	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>
  設(shè)置屬性后的時間:${time} }
  br>
  
 /body>
/html>

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

到此這篇關(guān)于JSP實時顯示當前系統(tǒng)時間的四種方式示例解析的文章就介紹到這了,更多相關(guān)JSP實時顯示當前系統(tǒng)時間內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • jsp實現(xiàn)頁面實時顯示當前系統(tǒng)時間的方法

標簽:大連 南京 黃石 廣州 貸款邀約 樂山 內(nèi)江 銅川

巨人網(wǎng)絡(luò)通訊聲明:本文標題《JSP實時顯示當前系統(tǒng)時間的四種方式示例解析》,本文關(guān)鍵詞  JSP,實時,顯示,當前,系統(tǒng),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《JSP實時顯示當前系統(tǒng)時間的四種方式示例解析》相關(guān)的同類信息!
  • 本頁收集關(guān)于JSP實時顯示當前系統(tǒng)時間的四種方式示例解析的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章