日期:2014-05-17  浏览次数:20700 次

怎么在有人访问我的网站的时候,记录下来总的访问人数,并在网页中显示出来???哪种方式最省时???
怎么在有人访问我的网站的时候,记录下来总的访问人数,并在网页中显示出来???有人说要建一个数据库专门记录访问量,有人说建库比较耗时。。。。到底什么方式最好???


------解决方案--------------------
application
------解决方案--------------------
探讨
application

------解决方案--------------------
用application 在启动项目的时候还原 在关闭的时候持久化
------解决方案--------------------
http://www.javaeye.com/problems/39671
------解决方案--------------------
呵呵 这是我用struts做的一个简单计数 你可以参考下 如果有更好的麻烦通知下谢谢
public class MyCount extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession(true);
String user = request.getParameter("user");
int newCount = (Integer) session.getAttribute(user) == null ? 1
: (Integer) session.getAttribute(user);
session.setAttribute("user", user);
if (session.getAttribute(user) != null) {
session.setAttribute(user, newCount + 1);
}else{
session.setAttribute(user, newCount);

response.sendRedirect("showCount.jsp");
}

}
------解决方案--------------------
用application对象实现网页计数器

<%--用application对象实现网页计数器peixun2.14.jsp文件代码--%>
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<head><title>网页计数器</title><head>
<body>
<% if (application.getAttribute("counter")==null)
application.setAttribute("counter","1");
else{
String strnum=null;
strnum=application.getAttribute("counter").toString();
int icount=0;
icount=Integer.valueOf(strnum).intValue();
icount++;
application.setAttribute("counter",Integer.toString(icount));
} %>
您是第<%=application.getAttribute("counter")%>位访问者!
</body>
</html>