时间:2021-04-16
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%>">
<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">
-->
</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%>">
<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">
-->
</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%>">
<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">
-->
</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%>">
<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">
-->
</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>
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
JSP显示当前系统时间的四种方式:第一种java内置时间类实例化对象:MyJSP'time4.jsp'startingpage第二种方式使用JSP内置USEBE
钻展推广四种方方式是什么?如果您想了解钻展推广四种方式请往下看小小编整理的钻展推广四种方式。感谢大家的支持和阅读。以下的内容供大家借鉴。 钻展推广四种方式
在jsp页面实现显示当前的日期时间,我们可以用一下两种方式实现:1.通过在jsp页面添加Java代码实现,主要代码如下所示java.text.SimpleDat
Android提供以下四种存储方式:SharePreferenceSQLiteFileContentProviderAndroid系统中数据基本都是私有的,一般
JSP的setProperty的使用方法一介绍作用给已经实例化的javabean对象的属性赋值,一共有四种形式。二四种形式三实例1、login.jspMyJSP