jsp用java运行当前时间_JSP显示当前系统时间的四种方式

本文介绍了JSP中显示当前系统时间的四种方法,包括使用java内置时间类、JSP内置USEBEAN、USEBEAN与beanName配对以及使用JSP setproperty设置属性。示例代码详细,可以直接应用于MYECLIPSE2010。文章由Joe.Smith于2016年9月29日在CSDN发布。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

JSP显示当前系统时间的四种方式:

第一种java内置时间类实例化对象:

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

My JSP 'time4.jsp' starting page

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);

%>

第二种方式使用JSP内置USEBEAN实例化时间类:

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

显示系统时间方法一:

现在时间:

第三种方式使用JSP USEBEAN type与beanName配对使用:

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

My JSP 'time2-useBean-type-beanName.jsp' starting page

现在时间:

第四种方式使用JSP setproperty设置属性:

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

My JSP 'time3-setproperty.jsp' starting page

jsp:setproperty 实例


设置属性后的时间:${time} }

所有代码均能直接复制到MYECLIPSE2010

版权说明

著作权归作者所有。

商业转载请联系作者获得授权,非商业转载请注明出处。

本文作者:Joe.Smith

发表日期:2016年9月29日

本文链接:http://blog.csdn.net/qq_26816591/article/details/52703122

来源:CSDN更多内容:JSP include指令与动作的相应时间对比

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值