First of all..NEVER I repeate NEVER store a database connection handle in
the HttpSession. This is a VERY bad thing to do. If your site grows..you can
forget about scalability. You'll be paying out the rear for licenses if you
have 1000's of users hit your site. At any rate, the first thing you need to
do is institue a connection pool for database connections. Second, have your
action class grab a connection at the start from this pool, then return it
at the end. Also, make sure you wrap everything up in a try..catch block and
catch Exception or better, Throwable and make sure you ALWAYS return the
connection (infact..put a finally{} block in that always returns the
connection.
Now, once that is done, here is the only thought I have on making sure a
session is terminated if they are done.
<body onUnload="closeSession()">
Now, write a javascript routine that submits a form or href link (or use an
applet on your site and have the javascript call the applet which then calls
through RMI or something to the server) to free any resources and invalidate
the session.
I am not sure how feasible this is. The only way I would really do this is
to have your entire site wrapped up into a two frame setup, with the first
frame being a hidden one with no size to it. Load an html page that loads in
the javascript that does the above..so that if they leave your site all
together, that little routine is called which will then close their session
info on the server. However, if you can't use frames in this manner, I am
not quite sure the above will work. The main reason is..each and every time
they go off of one page..even if they are going to another page on your
site, that javascript routine will be fired. I suppose you can have all
links and for submissions set a flag if they are clicked that is then
checked by that routine. If the flag is set, it jumps to the link clicked.
If the flag is not set, it submits the post to close the session (indicating
they are leaving your site).
Let us know what you come up with.
> -----Original Message-----
> From: Michael Mok [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, January 23, 2001 3:50 PM
> To: [EMAIL PROTECTED]
> Subject: Off Topic:: How do detect if user is still using your web
> application?
>
>
> Hi
>
> This is a fundamental problem facing all web applications. Due to the
> asynchronous nature of Web pages, it is almost impossible to
> establish if
> the user is still "using" the application.
>
> In the client/server world. the user session
> terminates/disconnects when
> they close the application.
>
> How do you implement this for web session? My application
> creates a new
> session when the users log on, connects them to their
> database and store
> their database connection handle to their session.
>
> The problem is that I do not know when to terminate their database
> connection. At present, my application terminates their
> connection when
> their session times out, when they click on the logout button
> (which usually
> never happens) or when the application gets shutdown.
>
> I would be interested hear how people handles this especially
> if STRUTS have
> any mechanism to cater for this type of situation.
>
> TIA
>
> Michael Mok
> www.webappcabaret.com/teatimej
>