当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JSP实时显示当前系统时间的四种方式示例解析

JSP实时显示当前系统时间的四种方式示例解析

2020年08月06日  | 移动技术网IT编程  | 我要评论
jsp显示当前系统时间的四种方式:第一种java内置时间类实例化对象:<%@ page language="java" import="java.util.*" pageencoding="ut

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实时显示当前系统时间内容请搜索移动技术网以前的文章或继续浏览下面的相关文章希望大家以后多多支持移动技术网!

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网