2012-08-08 2 views
0

사용자 세션이 만료 될 때 java를 사용하여 데이터베이스 행을 업데이트하는 방법은 무엇입니까? 이 상황에는 이 포함됩니다. 1. 사용자가 로그 아웃 버튼을 클릭하지 않습니다. 2.if가 자동으로 닫힙니다. 3. 시스템의 전원이 직접 꺼지는 상태입니다.사용자 세션이 만료 될 때 데이터베이스 행을 업데이트하는 방법, java?

때문에, 이러한 상황에서 (sessiondistroyed) (sessioncreated)하지만, 난 (httpsessionlistner을 사용했다

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"); 
} 

로그 아웃 클릭 condion)에서 다음 코드를 사용하여 DB의 row.now 스피을 업데이트 할 수있는 방법 sessioncreated 세션이 만료 될 때마다 sessiondistroyed가 호출되지 않습니다.

+0

어떻게 sessionDestroyed()가 호출되지 않는다는 것을 알고 계십니까? –

+1

나는 sessioncreated와 sessiondistroyed 모두를 위해 console msg를 사용했다. 그러나 sessioncreated msg는 evry time으로 인쇄되고, 새로운 로그인이 발생하지만 sessiondistroyed는 sessiondistroyed 내부에서 사용되는 System.out.println 메시지를 인쇄하지 않는다.) –

답변

0

HttpSession.invalidate()을 사용하여 강제로 세션 무효화를 수행하면 sys.xml이 인쇄되거나 세션이 자동 만료 될 때까지 기다릴 수 있습니다.

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

사용자 세션이 만료 될 때 데이터베이스 행을 업데이트하는 방법은 무엇입니까? 나는 HttpSession.invalidate()를 작성했지만, 브라우저가 상황을 어떻게 처리 할 것인가를 닫으면 ... –

+0

@Praveen - web.xml에 자동 만료를 구성하는 이유는 –

+0

kk입니다. 이제 기본값으로 설정됩니다 (30 분) ..하지만 내가 직접 브라우저를 닫으려고했는데 db에 대한 해당 작업 행이 업데이 트되지 않습니다 .. 그 행이 그 행을 이행하지 않는 경우 해당 행을 잠그기 위해 1로 업데이트된다는 의미입니다. 로그 아웃 버튼을 클릭하면 그 행은 바로 다른 사용자에게 할당됩니다. 즉 '0'이어야합니다. –

관련 문제