2012-08-08 80 views
0

使用java如何在用戶會話過期時更新數據庫行? 這種情況包括 1.用戶不點擊任何註銷按鈕 2.如果自動關閉瀏覽器。 3.系統直接關機狀態。如何在用戶會話過期時使用java更新數據庫行?

所以,在這些情況下如何使用下面的代碼在註銷點擊condion

Connection con = (Connection) new DB2Connection().getDatabaseConnection(); 
if(request.getParameter("flrmdn") != null) 
{ 
String s1=request.getParameter("flrcaf"); 
String s2=request.getParameter("flrmdn"); 

String sql1="update table2 set FLRReference=0 where CAF='"+s1+"' and  MDN='"+s2+"' and FLRReference=1 "; 
Statement st1=con.createStatement(); 
int vupdate=st1.executeUpdate(sql1); 
} 
else if(request.getParameter("indexmdn") != null) 
{ 
String indexcaf=request.getParameter("indexcaf"); 
String indexmdn=request.getParameter("indexmdn"); 

String sql="update table set IndexReference=0 where CAF='"+indexcaf+"' and MDN='"+indexmdn+"' and IndexReference=1 "; 
Statement st=con.createStatement(); 
int entryrows=st.executeUpdate(sql); 
} 


// Redirecting user to actual required page 

if(request.getParameter("location").equalsIgnoreCase("login")) 
{ 
response.sendRedirect("login.jsp?logout=true"); 
} 

我已經使用httpsessionlistner(),sessioncreated(),sessiondistroyed(),但在可更新DB row.now IAM sessioncreated會自動調用,但會話過期時不會調用sessiondistroyed

+0

你怎麼知道sessionDestroyed()沒有被調用? – 2012-08-08 11:33:30

+1

我已經使用控制檯消息會話創建和sessiondistroyed ..但會話創建消息打印evry時間,一個新的登錄發生,但同一時間sessiondistroyed不會打印System.out.println消息,(這是在sessiondistroyed內使用。 ) – 2012-08-08 11:54:40

回答

0

使用HttpSession.invalidate()強制會話失效,您可以看到系統輸出已打印或等待會話自動過期,方法如下所示,在web.xml中指定。

<session-config> 
     <session-timeout>5</session-timeout> 
</session-config> 
+0

如何在用戶會話過期時更新數據庫行?我已經寫了HttpSession.invalidate(),但如果瀏覽器直接關閉什麼情況下,它不會調用.... – 2012-08-08 12:05:03

+0

@Praveen - 這就是爲什麼你配置web.xml中的自動失效 – 2012-08-08 12:12:37

+0

kk現在它被設置爲默認30分鐘)..但是當我試圖直接關閉瀏覽器...相應的數據庫工作行不更新..我的意思是行更新爲1鎖定該用戶,如果該用戶不滿足行,並沒有點擊註銷按鈕,該行應該分配給其他用戶。即應該是'0' – 2012-08-08 12:29:21

相關問題