栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

java每周统计展示

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java每周统计展示

一:工程截图:

二:运行效果图:

三:CountObjectInfo.java:

package cn.csrc.base.count;

import java.util.Date;

public class CountObjectInfo {

// 总访问量合计

protected int totalCount = 0;

// 日访问量

protected int dayCount = 0;

// 周访问量

protected int weekCount = 0;

// 月访问量

protected int monthCount = 0;

// 年访问量

protected int yearCount = 0;

// 临时访问量

protected int tempCount = 0;

protected Date date = new Date();

public int getDayCount() {

return dayCount;

}

public int getMonthCount() {

return monthCount;

}

public int getTotalCount() {

return totalCount;

}

public int getWeekCount() {

return weekCount;

}

public int getYearCount() {

return yearCount;

}

public void setDayCount(int i) {

dayCount = i;

}

public void setMonthCount(int i) {

monthCount = i;

}

public void setTotalCount(int i) {

totalCount = i;

}

public void setWeekCount(int i) {

weekCount = i;

}

public void setYearCount(int i) {

yearCount = i;

}

public Date getDate() {

return date;

}

public void setDate(Date date) {

this.date = date;

}

public int getTempCount() {

return tempCount;

}

public void setTempCount(int i) {

tempCount = i;

}

}

四:CountXml.java:

package cn.csrc.base.count;

import java.io.FileReader;

import java.io.FileWriter;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

import org.exolab.castor.xml.Marshaller;

import org.exolab.castor.xml.Unmarshaller;

public class CountXml {

private String fileName = "E:\workspace\Count\WebContent\WEB-INF\xmlcount.xml";

private static CountObjectInfo obj = null;

private static CountXml instance = null;

public static CountXml getInstance() {

if (instance == null) {

instance = new CountXml();

}

return instance;

}

private CountXml() {

try {

obj = read(fileName);

} catch (Exception e) {

System.out.println(e);

}

}

public int getTotalCount() {

return obj.getTotalCount();

}

public int getDayCount() {

return obj.getDayCount();

}

public int getMonthCount() {

return obj.getMonthCount();

}

public int getWeekCount() {

return obj.getWeekCount();

}

public int getYearCount() {

return obj.getYearCount();

}

public synchronized void addcount(Date da) {// 比较日期增加计数

if (new SimpleDateFormat("yyyy-MM-dd").format(this.obj.date).equals(

new SimpleDateFormat("yyyy-MM-dd").format(da)))

this.obj.setDayCount(this.obj.getDayCount() + 1);

else

this.obj.setDayCount(1);

if (new SimpleDateFormat("yyyy-MM").format(this.obj.date).equals(

new SimpleDateFormat("yyyy-MM").format(da)))

this.obj.setMonthCount(this.obj.getMonthCount() + 1);

else

obj.setMonthCount(1);

Calendar ca = Calendar.getInstance();

ca.setTime(da);

ca.setFirstDayOfWeek(Calendar.MONDAY);

if (ca.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY

&& !new SimpleDateFormat("yyyy-MM-dd").format(this.obj.date)

.equals(new SimpleDateFormat("yyyy-MM-dd").format(da)))

obj.setWeekCount(1);

else

obj.setWeekCount(obj.getWeekCount() + 1);

if (new SimpleDateFormat("yyyy").format(this.obj.date).equals(

new SimpleDateFormat("yyyy").format(da)))

this.obj.setYearCount(this.obj.getYearCount() + 1);

else

obj.setYearCount(1);

obj.setDate(da);

obj.setTotalCount(obj.getTotalCount() + 1);

obj.setTempCount(obj.getTempCount() + 1);

if (obj.getTempCount() >= 0) {// 只有当临时访问量大于等于20时才保存一次

obj.setTempCount(0);// 临时计数器置0

write(fileName);

}

}

private void write(String fileName) {

try {

FileWriter writer = new FileWriter(fileName);

Marshaller.marshal(obj, writer);

writer.close();

} catch (Exception e) {

System.out.println(e);

}

}

private CountObjectInfo read(String fileName) throws Exception {

FileReader reader = new FileReader(fileName);

CountObjectInfo result = (CountObjectInfo) Unmarshaller.unmarshal(

CountObjectInfo.class, reader);

reader.close();

return result;

}

}

五:index.jsp:

pageEncoding="UTF-8"%>

计算器测试

计算器测试

CountXml xmlcount = CountXml.getInstance();

if (session.isNew()) {

xmlcount.addcount(new Date());//增加访问量

int n = xmlcount.getTotalCount();//取总访问量

String count = Integer.toString(n);

session.putValue("count", count);

}

%>

您是第位访问者

总访问量:

本年访问量:

本月访问量:

本周访问量:

本日访问量:

六:xmlcount.xml文件的初始内容如下:

七:源码下载地址:http://download.csdn.net/detail/sxdtzhaoxinguo/7615273

八:程序参考地址:http://bujingyun23.blog.163.com/blog/static/18131024320131594942633/

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/984632.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号