//問題
謝謝您,可是用session怎麼能將客戶端的正在浏覽的url不斷發送到服務器端呢?難道要在客戶端做個什麼東西,在嵌個浏覽器?please give me a hint,thx!
//回答,用sessionListener[Session監聽器來實現]
//下邊是一個監器的源碼,實現了在線人數,依此原理,你能做你想要做的
package core;
/**
* Title: core
* Description:
* Copyright: Copyright (c) 2001
* Company: ****
* @author 羅亭
* @version 1.0
*/
import Javax.servlet.*;
import Javax.servlet.http.*;
public final class CounterListener implements HttpSessionListener {
private int count = 10;
private ServletContext context = null;
public synchronized void sessionCreated(HttpSessionEvent se) {
count++;
log("sessionCreated('" + se.getSession().getId() + "'LuoTing's Log)"+" count="+count);
se.getSession().setAttribute("count",new Integer(count));
}
public synchronized void sessionDestroyed(HttpSessionEvent se) {
count--;
se.getSession().setAttribute("count",new Integer(count));
}
public int getCount() {
return this.count;
}
public void addCount(){
count++;
}
private void log(String message) {
if (context != null)
context.log("SessionListener: " + message);
else
System.out.println("SessionListener: " + message);
}
}
//這就是一個監聽器的源碼,已經在Tomcat4.01上測試過[Tomcat3.1是不成的,其余app server的實現情況,得看它的DOCS]
//這個監聽器需在你的web.XML中注冊
//like this
//放置的位置你放到它的示例後邊即可
Good Lucky