• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question abt session and need advise in designing the project

 
Subha Rangu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am developing an application which searches for a particular document in some kind of database and returns the results and when the user clicks on one of the results, it should show the corresponding document from the db. Now I could get that functionality in my app. But my question is right now I am planning to store the document in temp folder and giving it back to the user for a particular session and am going to use a file name specific to the session and particular document for storing the docs.
My questions:
I want to delete the file after the session times out/user closes the window.How do I do that?

And also please advise me if the whole thing is the right approach to achieve the functionality of the application considering the performance issues. I am using JSP and java classes right now.

I am completely a beginner and was asked to develop this application on my own.
Please help me out.
Thanks
 
Jeffrey Hunter
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your design should incorporate a Servlet to control access and document retrieval from the database. What format are the documents using and how are they stored in the db? Answers to these questions will influence design decisions, so you need to address these first. Do you even need to create a temporary file?

As far as capturing a browser close event, good luck. As far as I know, there is no straightforward means to notify the server when a client has closed the browser. I've used a hack involving the javascript call onbeforeunload() in body tag, but this strategy is not bulletproof.

If you assume your clients are well-behaved (we can dream can't we?), and will logout appropriately, you can explicitly kill a session (session.invalidate()) upon logout (or some other mechanism triggered by the user). You'd use a class which implements the HttpSessionBindingListener interface to control clean-up activities. If your clients are not well-behaved, you're left to rely on the session timeout, so clean-up activities will be delayed until the session times out.
[ August 26, 2004: Message edited by: Jeffrey Hunter ]
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bubly,

Your outline design sounds reasonable to me.

Forget about trying to determine if the user has closed the browser; you can't do that reliably and you don't need to, so it's not worth trying.

You want to clean up (delete unwanted files) when the user explicitly logs out (if they ever do), when their session times out and when the application starts up (note, not when it shuts down as if it goes out with a bang this won't get done - you can do both if you prefer). So the implementation of two out of three of those options is fairly self-evident.

The other one, session timeouts, requires that you implement the HTTPSessionListener interface and use the sessionDestroyed() method (not the HTTPSessionBindingListener interface; that's something else). You will need to configure your web app, using the deployment descriptor (web.xml) to notify your servlet of session lifecycle events; i.e. the container registers your servlet as an HTTPSessionListener.

This might sound a little daunting if you're an absolute beginner so I suggest you look up the stuff in a book or a web tutorial to familiarise yourself with the concepts involved.

Hope this helps.

Jules
 
Jeffrey Hunter
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some clarification -- how you deal with session cleanup very much depends on the architecture of your application. I've used JavaBeans as DAOs (Data Access Object), in which case, each Bean, as it is part of a session, is responsible for cleaning itself up when the session is invalidated. This promotes reusability as each Bean essentially can be "plugged-in" to existing web apps without addressing the underlying session control implemented by the web app (particularly the deployment descriptor). Furthermore, if the Bean itself becomes unbound, yet the session remains valid, the Bean can perform its cleanup. The Beans implement the HttpSessionBindingListener interface to become aware of the session to which they belong.

On the other hand, if you don't require such fine-grained control, you should use the HttpSessionListener, in which case the application itself becomes responsible for cleanup.
 
Subha Rangu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all your advices. I will go ahead and try and will get back to you if anything works out or not
Thanks
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic