亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

瀏覽:219日期: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
主站蜘蛛池模板: 九九热在线视频免费观看 | 九九热香蕉视频 | 国产成人亚洲综合无 | 污视频网址 | 黄色录像一级片 | 久久精品国产一区二区三区日韩 | 亚洲高清视频在线 | 亚洲一区二区三区福利在线 | 久久9966精品国产免费 | 日韩亚洲欧美综合 | 久久本道久久综合伊人 | 91精品久久一区二区三区 | 1000部拍拍拍18免费网站 | 最新在线精品国自拍视频 | 免费国产草莓视频在线观看黄 | 免费看三级黄色片 | 操亚洲美女 | 久久99国产精品一区二区 | 黄色毛片视频网站 | 国产精品88 | 色综合亚洲综合网站综合色 | 国产jav| 天天影视欲香欲色成人网 | 韩国女主播精品一区二区 | 国产在线成人a | 日本精品在线观看视频 | 久草a视频| 国产又色又爽又黄的网站在线一级 | 免费影院在线观看 | 亚洲一级黄色片 | 91精品国产综合久久福利 | 日本人爱爱视频 | 在线一级黄色片 | 黄色一级片性生活 | 一级做a毛片免费视频 | 国产不卡视频一区二区在线观看 | 欧美大片毛片aaa免费看 | 婷婷色综合| 久久欧美久久欧美精品 | 182tv免费福利夜在线观看 | aaa一级黑人毛片 |