校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

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

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

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

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

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

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

您可能感興趣的文章:
  • jsp實現頁面實時顯示當前系統時間的方法

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

巨人網絡通訊聲明:本文標題《JSP實時顯示當前系統時間的四種方式示例解析》,本文關鍵詞  JSP,實時,顯示,當前,系統,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《JSP實時顯示當前系統時間的四種方式示例解析》相關的同類信息!
  • 本頁收集關于JSP實時顯示當前系統時間的四種方式示例解析的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 山西省| 涡阳县| 宁阳县| 宣恩县| 施秉县| 肇东市| 日照市| 夏津县| 三门峡市| 洛阳市| 枝江市| 封丘县| 夹江县| 平塘县| 老河口市| 北宁市| 阳原县| 临猗县| 淅川县| 大冶市| 七台河市| 大城县| 枣阳市| 克什克腾旗| 呼玛县| 赤水市| 兴和县| 上杭县| 光山县| 鄢陵县| 益阳市| 肥东县| 田东县| 望谟县| 博白县| 友谊县| 榕江县| 内乡县| 腾冲县| 六安市| 来安县|