有两种方法,一是自己写,二是用别人的
你要现成的,只需要在google里搜"免费计数器",就会有一堆的,一般是你注册一下相关信息(主要是你的网站链接),它就会给你生成一段代码,你把这段代码拷到你的网页里面就可以了.
你要现成的,只需要在google里搜"免费计数器",就会有一堆的,一般是你注册一下相关信息(主要是你的网站链接),它就会给你生成一段代码,你把这段代码拷到你的网页里面就可以了.
解决方案 »
- select></select>下拉菜单中的文字如何垂直居中
- jsp页面传值有哪些方式(急,最好详细说一下)
- <label class="error" for="treeValue" generated="true">请您为当前用户分配平台!</label>
- 刚刚学习,不知道我应该如何还原这个jar文件?谢谢。
- 字节数组怎么转换成二进制字符串
- 求助struts+hibernate+jsp结合tomcat-5作的网站出现的问题
- 为什么仍然会跳转呢?
- 当鼠标光标移动到层内的图片时如何才能执行一代码。如下
- (talk)网站的自动登陆功能的小软件该如何完成?
- 如何得到ResultSet中记录的条数?
- 怎么可能啊:method readLine()错误,请大家无必帮我瞧下,谢谢!
- 今天出现了怪事。。我以前用access中的自动编号 如 rs=sql.e
//Author:fancy
//Date:2001.3.26
//Note:use this JavaBean to Counter!
package test;public class Counter
{
int Count=1;
public void Counter()
{
}
public void addCount()
{
Count++;
}
public int getCount()
{
return Count;
}
}**************************************************************<%--
File Name:useCounter.jsp
Author:fancy
Date:2001.3.26
Note:use javabean to say hello world!
--%>
<jsp:useBean id="counter" scope="application" class="test.Counter" />
<br>
你好你是第
<%
out.println(counter.getCount());
counter.addCount();
%>位访客
blog里就有的
<html>
<head>
<title>
jsp1
</title>
</head>
<body bgcolor="#ffffff">
<%! int i=0; %>
<% i++; %>
<%="计数器"+i%>
</body>
</html>
<%@ page contentType="text/html;charset=gb2312"%>
<HTML>
<HEAD>
<BODY>
<jsp:useBean class="zhao.SessionCounter" id="sessionCounter" scope="application" />
总计<jsp:getProperty name="sessionCounter" property="totalSessionCount" />
当前在线<jsp:getProperty name="sessionCounter" property="currentSessionCount" />
最大访问数量<jsp:getProperty name="sessionCounter" property="maxSessionCount" />
</BODY>
</HTML>
import javax.servlet.*;
import javax.servlet.http.*;public class SessionCounter implements HttpSessionListener {
private int totalSessionCount = 0;
private int currentSessionCount = 0;
private int maxSessionCount = 0;
private ServletContext context = null;
public void sessionCreated(HttpSessionEvent event) {
System.out.println("Created!");
totalSessionCount++;
currentSessionCount++;
if (currentSessionCount > maxSessionCount) {
maxSessionCount = currentSessionCount;
}
if (context == null) {
storeInServletContext(event);
}
} public void sessionDestroyed(HttpSessionEvent event) {
System.out.println("Destroyed!");
currentSessionCount--;
}
public int getTotalSessionCount() {
return(totalSessionCount);
}
public int getCurrentSessionCount() {
return(currentSessionCount);
} public int getMaxSessionCount() {
return(maxSessionCount);
}
private void storeInServletContext(HttpSessionEvent event) {
HttpSession session = event.getSession();
context = session.getServletContext();
context.setAttribute("sessionCounter", this);
}
}
把这个编译一下就可以了
。
<%@ page import="java.io.*" %>
<HTML>
<BODY BGCOLOR=cyan><FONT Size=1>
<%! int number=0;
synchronized void countPeople()//计算访问次数的同步方法
{
if(number==0)
{
try{
FileInputStream in=new FileInputStream("count.txt");
DataInputStream dataIn=new DataInputStream(in);
number=dataIn.readInt();
number++;
in.close();
dataIn.close();
}
catch(FileNotFoundException e)
{ number++;
try {FileOutputStream out=new FileOutputStream("count.txt");
DataOutputStream dataOut=new DataOutputStream(out);
dataOut.writeInt(number);
out.close();dataOut.close();
}
catch(IOException ee){}
}
catch(IOException ee)
{
}
}
else
{number++;
try{
FileOutputStream out=new FileOutputStream("count.txt");
DataOutputStream dataOut=new DataOutputStream(out);
dataOut.writeInt(number);
out.close();dataOut.close();
}
catch(FileNotFoundException e){}
catch(IOException e){}
}
}
%>
<%
countPeople();
%>
<P><P>您是第
<%=number%>
个访问本站的客户。
<BODY>
<HTML>
比如
application.setAttribute("counter","0");
每进来一个就使application的变量加1
然后用
application.getAttribute("counter");获取啊
Cookie防止按F5刷新,然后Jsp负责记录
可以记录到数据文件或者数据库