Solved

how to discorrect from database using JavaBean when user click on "logout" button?

Posted on 2004-04-28
3
267 Views
Last Modified: 2008-02-26
dear experts,

I created a logout button on my JSP page, but not sure how to implement it correctly.
if I just call window.close(), then this button does not really disconnect from database when the window is close.
but, i am using JavaBean to call the database object to connect and disconnect from database. however, there are several JavaBeans on each page. if I want to create a "generic" logout button that I can put it on every page, it will call every JavaBean to disconnect from database.

How to do this? is the right way to design the logout button? thanks.
0
Comment
Question by:sarahchi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
searlas earned 25 total points
ID: 10943428
First things first, you shouldn't have a Connection per bean, or even a Connection per user.  You should have a Connection pool, which you quickly borrow a connection from, make a database call, and return it to the pool ready to be used by something else.  This is built into application servers via the use of DataSources.  See:
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Resources3.html

Secondly, you must not rely on users being well behaved (i.e. clicking logout).

Now, ploughing on regardless... if a bean holds a connection to the db, and the bean is held in a session (i.e. the bean is unique to a user, not shared between many users.)  You could get your beans to implement HttpSessionBindingListener; having an empty implementation for the valueBound method, and creating an implementation for valueUnbound that closes the connection to the database.  Your logout button could iterate over all attributes stored in the session, removing them one by one (thereby causing their valueUnbound methods to be called.)  Then you'd call session.invalidate(); to complete the logout action.

http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpSessionBindingListener.html
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
issue with pdf generation 2 96
gZip compression filter 2 182
Reading data  from excel sheet and displaying 1 92
oracle fusion vs MQ 2 128
Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
This article discusses how to implement server side field validation and display customized error messages to the client.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question