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实时显示当前系统时间内容请搜索万象站长学堂以前的文章或继续浏览下面的相关文章希望大家以后多多支持万象站长学堂!
您可能感兴趣的文章


阅读排行
- 1电脑无声音提示Windows音频错误0xc00d11d1(0xc00d4e86)的解决办法..
- 2C盘文件怎么转移到d盘? 将电脑C盘文档转移到D盘的多种技巧汇总..
- 3电脑运行快捷指令怎么打开? 打开运行命令框的方法汇总..
- 4发票打印提示缺少字体怎么解决? 电脑显示缺少发票打印字库的处理方法..
- 5无线网卡插电脑上没没有网络怎么办? 电脑不识别无线网卡的解决办法..
- 6录音功能在哪里? 电脑手机等设备打开录音功能的技巧..
- 7电脑卸载流氓软件的5个隐藏技巧 实测有效
- 8电脑开机进不去系统提示0xc0000428怎么办? 0xc0000428错误代码解决办法..
- 9电脑没有网连不上wifi怎么办? 电脑网络连接不上的多种解决办法..
- 10消灭机械硬盘!固态硬盘的选购和使用
推荐教程
- 1电脑无声音提示Windows音频错误0xc00d11d1(0xc00d4e86)的解决办法..
- 2C盘文件怎么转移到d盘? 将电脑C盘文档转移到D盘的多种技巧汇总..
- 3电脑运行快捷指令怎么打开? 打开运行命令框的方法汇总..
- 4发票打印提示缺少字体怎么解决? 电脑显示缺少发票打印字库的处理方法..
- 5无线网卡插电脑上没没有网络怎么办? 电脑不识别无线网卡的解决办法..
- 6录音功能在哪里? 电脑手机等设备打开录音功能的技巧..
- 7电脑卸载流氓软件的5个隐藏技巧 实测有效
- 8电脑开机进不去系统提示0xc0000428怎么办? 0xc0000428错误代码解决办法..
- 9电脑没有网连不上wifi怎么办? 电脑网络连接不上的多种解决办法..
- 10消灭机械硬盘!固态硬盘的选购和使用


粤公网安备 13010202004186