0
如何使用httpsessionbindinglistner跟蹤註銷時間?我已經給出了示例代碼並在下面給出,但它不起作用。 RESOURCE IS HERE使用HttpSessionBindingListeners跟蹤註銷時間
package com.tunatore.listeners;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
/**
*
* @author tunatore
*/
public class ObjectWillBeInSession implements HttpSessionBindingListener{
private String property1 = null;
private String property2 =null;
@Override
public void valueBound(HttpSessionBindingEvent event) {
//code to run when ObjectWillBeInSession object associated with a http session
}
@Override
public void valueUnbound(HttpSessionBindingEvent event) {
//code to run when ObjectWillBeInSession object removed from a http session
//logging into a database server could be done here
/**
* @return the property1
*/
public String getProperty1() {
return property1;
}
/**
* @param property1 the property1 to set
*/
public void setProperty1(String property1) {
this.property1 = property1;
}
/**
* @return the property2
*/
public String getProperty2() {
return property2;
}
/**
* @param property2 the property2 to set
*/
public void setProperty2(String property2) {
this.property2 = property2;
}
}
logout.jsp //這裏我想插入註銷時間到數據庫關閉瀏覽器時或會話超時發生
<%
ObjectWillBeInSession owi = new ObjectWillBeInSession();
owi.setProperty1("I am a value for Property1");
owi.setProperty2("I am a value for Property2");
//this will call HttpSessionBindingListener's
//valueBound method for the object
session.setAttribute("owi", owi);
//this will call HttpSessionBindingListener's
//valueUnbound method for the object
session.removeAttribute("owi");
//INSERT INTO DB.......BUT IT IS NOT WORKING
%>
yikes!感謝Ravindra,但是logout.jsp有沒有代碼錯誤? – Tom 2012-03-22 09:44:47
不會。註銷時不會有任何錯誤。 – 2012-03-22 09:46:48
好吧,但[這裏](http://stackoverflow.com/questions/9425476/lock-logged-in-user-in-oracle-by-java)Jigar通過使用Binding Listener解釋 – Tom 2012-03-22 09:54:51