JavaBean在JSP中显示时间
创建DateTimeBean的类,将其放置于org.caiduping.bean的包中,实现时间,星期的封装。
package org.caiduping.bean; import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date; public class DateTimeBean {
private String dateTime;
private String week;
//Calendar对象
private Calendar calendar=Calendar.getInstance();
/*
* 获取日期和时间
*
* */
public String getdateTime(){
//获取当前时间
Date currDate=Calendar.getInstance().getTime();
//实例化SimpleDateFormat
SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 HH点mm分ss秒");
//格式化日期时间
dateTime=sdf.format(currDate);
return dateTime;
}
/*
* 获取星期几
*
* */
public String getweek(){
//定义数组
String[] weeks={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
//获取一星期的某天
int index=calendar.get(Calendar.DAY_OF_WEEK);
//获取星期几
week=weeks[index-1];
return week; }
}
而index.jsp则实例化DateTimeBean对象:
<%@ 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>
<style type="text/css">
#clock{
width:500px;
height:100px;
padding-top: 20px;
border:solid 5px black;
}
#week{
padding-top: 20px; }
</style>
<meta http-equiv="Refresh" content="1">
<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="date" class="org.caiduping.bean.DateTimeBean"></jsp:useBean>
<div id="clock">
<div id="time">
<jsp:getProperty property="dateTime" name="date"/>
</div>
<div id="week">
<jsp:getProperty property="week" name="date"/>
</div>
</div>
</body>
</html>
JavaBean在JSP中显示时间的更多相关文章
- 在LINUX的命令提示符及CMD命令提示符中显示时间
用途之一是可以查看某个命令或程序的执行时间. 一.CMD中显示时间设置 参数说明: $P:当前路径 $G:>(大于号) $T:当前时间,精确到0.01s 实验如下: C:\Users\g4-10 ...
- JavaBean在jsp中的使用
JavaBean在Jsp中的引用: 1.用<jsp:useBean>标记: <jsp:useBean id="name" class="classnam ...
- javabean解决jsp中中文乱码问题
问题描述:useBean行为定义了Java Bean对象(Person类包括姓名[string],年龄[int]),使用html页面向JSP页面提交数据,JSP页面中使用Java Bean行为来处理提 ...
- 【ModelMap】jsp中显示springmvc modelmap传递的对象
最近在做一个小网站,功能非常基础,决定用springmvc搭建. 遇到一个问题,在controller向前端传值时,比如使用ModelMap传了一个字符串,modelmap.addattribute( ...
- 如何在jsp中显示数据库的内容
用Eclipse tomcat新建一个JSP页面(一)介绍了如何创建一个web程序和第一个jsp页面,以及Eclipse需要的一些必要配置.今天,我们重点说一下如何从数据库中查询数据,并且在JSP页面 ...
- 火狐低版本中显示时间格式为:yyyy-MM-dd hh:mm:ss,出现NaN
在低版本的火狐(43以下)和IE8中,显示时间格式为:yyyy-MM-dd hh:mm:ss,会出现NaN:原因是只支持yyyy/MM/dd hh:mm:ss; 所以在new Date('2018-0 ...
- 读取数据库数据,并将数据整合成3D饼图在jsp中显示
首先我将生成饼图的方法独立写成一个PieChar.java类,详细代码如下:(数据库需要自己建,如有需要的话) import java.io.IOException; import java.sql. ...
- 大学jsp实验七--JavaBean在JSP中的应用
值bean的应用 (1)若有如下图所示的两个JSP页面,在第一个的页面的表单中填写相应内容,提交后再显示用户的提交信息.使用JavaBean的方式实现上述效果,请写出相应的代码. bean文件:Tes ...
- Jsp页面显示时间:<fmt>标签问题
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%> <%@ taglib ...
随机推荐
- Spring和Hibernate集成的HibernateTemplate的一些常用方法总结
1:get/load存取单条数据 public Teacher getTeacherById(Long id) { return (Teacher)this.hibernateTemplate.get ...
- wiki1169-传纸条(dp)
http://wikioi.com/problem/1169/ 四维数组和三维数组: #include<iostream> #include<cstdio> #include& ...
- Educational Codeforces Round 1 D. Igor In the Museum bfs 并查集
D. Igor In the Museum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598 ...
- 【PAT Advanced Level】1008. Elevator (20)
没什么难的,简单模拟题 #include <iostream> using namespace std; int main() { int num; cin>>num; int ...
- w3cmark前端精彩博文周报 10.27-11.2
w3cmark 官方Q群 145423956 | 官方微博 @w3cmark 这周周报来迟了,公司真的好忙!!!欢迎关注我们的微博 @w3cmark w3cmark推出每周精选前端博文推荐,通过阅读别 ...
- delphi Edit - TActionList
Edit TEditCut TEditCopy TEditpaste TEditSelectAll TEditUndo TEditDelete 编辑 ...
- ElasticSearch使用
安装之前,请参考https://github.com/richardwilly98/elasticsearch-river-mongodb根据你的MongoDB版本号决定需要的elasticsearc ...
- HDFS原理讲解
简介 本文是笔者在学习HDFS的时候的学习笔记整理, 将HDFS的核心功能的原理都整理在这里了. [广告] 如果你喜欢本博客,请点此查看本博客所有文章:http://www.cnblogs.com/x ...
- ASCII与UNICODE的区别
1.ASCII的特点 ASCII 是用来表示英文字符的一种编码规范.每个ASCII字符占用1 个字节,因此,ASCII 编码可以表示的最大字符数是255(00H—FFH).这对于英文而言,是没有问题的 ...
- A beginner’s guide to Cache synchronization strategies--转载
原文地址:http://vladmihalcea.com/2015/04/20/a-beginners-guide-to-cache-synchronization-strategies/ Intro ...