Ⅰ java web 网站访问量统计 设计求解答
如果后续需要用到这部分数据,肯定是要做持久化的。 统计处理可以精细化到具体页面(这个要看表结构如何设计了) 页面处理建议在action中直接入库及访问数据展示~ 或js页面初始化时ajax入库
Ⅱ java怎么统计网站访问量
<DIV class="h">
<%-- 记录网站访问次数 --%>
<%
Integer counter = (Integer)application.getAttribute("counter"); //先从application里面获取计数器的key的值
if(counter==null){
//如果该值为null,说明第一次访问
application.setAttribute("counter",1);
counter=(Integer)application.getAttribute("counter");
}else {
//如果该值不为空,取出来进行累加
int i = counter.intValue();
i++;
application.setAttribute("counter",i);//累加后再放进去
}
%>
<% User user =(User)session.getAttribute("users"); %>
<%="欢迎"+user.getName() %> |您是第<%=counter.intValue()%>位访客
</DIV>
Ⅲ 网站统计不同区域的访问量java 和mysql语句实现 。 谢谢!
大约要三张表
A表(地区名):
地区代码 地区名 总访问次数
1 广东省 0
2 江苏省 0
...
B表(日访问表)
地区代码 访问时间 日访问次数
1 20131224 0
8 20131224 0
C表(ip来源表)
序号 来访IP 地区代码 时间
处理流程基本上就是
1、先取用户ip,从ip库中查询出用户地区(这种代码随处可以找到,比如http://zhaoshijie.iteye.com/blog/1171132)一般就是纯真ip库,有了地区后,从A表中查出地区代码
2、向C表中添加记录
3、然后查一下B表有没有当日该地区记录,如果没有就在B表中新增一条,如果有就将B表对应的次数加1,然后A表中对应地区代码次数统计也加1
然后比如你要查2013年12月24日的各地区统计就可以是
select * from a,b where a.地区代码=b.地区代码 and b.访问时间=20131224
Ⅳ 网站访问量统计java代码
public class Counter {
private int count;
// 每访问一次,计数器自加一
public int getCount() {
return ++count;
}
public void setCount(int count) {
this.count = count;
}
}
<%-- 定义一个 session 范围内的计数器 记录个人访问信息 --%>
<jsp:useBean id="personCount" class="com.helloweenvsfei.jspweb.bean.Counter" scope="session" />
<%-- 定义一个 application 范围内的计数器 记录所有人的访问信息 --%>
<jsp:useBean id="totalCount" class="com.helloweenvsfei.jspweb.bean.Counter" scope="application" />
<div align="center">
<form action="method.jsp" method="get">
<fieldset style='width: 300'>
<legend>计数器</legend>
<table align="center" width="400">
<tr>
<td width=150 align="right" style="font-weight:bold; ">您的访问次数:</td>
<td>
<%-- 获取个人的 访问次数 --%>
<jsp:getProperty name="personCount" property="count" /> 次
</td>
</tr>
<tr>
<td width=150 align="right" style="font-weight:bold; ">总共的访问次数:</td>
<td>
<%-- 获取所有人的 访问次数 --%>
<jsp:getProperty name="totalCount" property="count" /> 次
</td>
</tr>
</table>
</fieldset>
</form>
</div>
希望你能帮到你
Ⅳ java怎么统计网站访问量
<DIV class="h">
<%-- 记录网站访问次数 --%>
<%
Integer counter = (Integer)application.getAttribute("counter"); //先从application里面获取计数器的key的值
if(counter==null){
//如果该值为null,说明第一次访问
application.setAttribute("counter",1);
counter=(Integer)application.getAttribute("counter");
}else {
//如果该值不为空,取出来进行累加
int i = counter.intValue();
i++;
application.setAttribute("counter",i);//累加后再放进去
}
%>
<% User user =(User)session.getAttribute("users"); %>
<%="欢迎"+user.getName() %> |您是第<%=counter.intValue()%>位访客
</DIV>
Ⅵ java如何统计session访问次数
1,Session
在JavaWeb中使用HttpSession(以下简称session)对象来表示一个会话。
正在装载数据…… Session的创建(代表会话周期的开始):第一次调用request.getSession()方法时,会创建一个session对象。
Session的销毁(代表会话周期的结束):在某个请求周期内调用了Session.invalidate()方法,此请求周期结束后,session被销毁;或者是session超时后自动销毁。
对于JSP,如果指定了<%@ page session="false"%>,则在JSP中无法直接访问内置的session变量,同时也不会主动创建session,因为此时JSP未自动执行request.getSession()操作获取session。
在session对象刚创建的第一个请求周期内,调用session.isNew()方法将得到true。
可以在web.xml文件中配置session默认的超时时间(分钟):
<session-config>
<session-timeout>10session-timeout>
session-config>
也可以调用session. setMaxInactiveInterval()方法设置session超时时间(分钟)
2,SessionListener
通过SessionListenr可以监听session的创建和销毁,步骤:
1.写一个类MySessionListener,实现javax.servlet.http.HttpSessionListener接口及其sessionCreated()、sessionDestroyed()方法
2.在web.xml中配置SessionListener:
<listener>
<listener-class>MySessionListener类全名listener-class>
listener>
当 session被创建和销毁时,容器会分别调用SessionListener的sessionCreated()方法和 sessionDestroyed()方法,这两个方法中传入了一个参数对象HttpSessionEvent,可以通过此对象的 getSession()方法获取session对象