Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

Associate a file to a servlet session

Thread view: 
senges - 12 Apr 2006 13:26 GMT
Hi,

for a certain servlet session i want to create some files (images)
which are session specific. When the session is invalid or gets
destroyed i want these files to be deleted.

Anyone has some experience with that issue?

Is there some kind of a session destructor which can notify me when the
session is destroyed so that i can delete the associated files?

What's the best way to associate files/artefacts with a specific
session?

Thanks for any help,
Chris
Ed Kirwan - 12 Apr 2006 14:23 GMT
> Hi,
>
[quoted text clipped - 12 lines]
> Thanks for any help,
> Chris

Not sure what the, "Best," way to associate artefacts with sessions is,
but a key question is: how secure do you want it?

I have a servlet which instantiates a Session based on a name and
password entered by the user. I then insert this name/password
combination in the HTTP sent back to the user, and map the name/password
to the session in the servlet.

When the user enters more input, the name/password are sent as fields to
the servlet, which then finds the appropriate Session to process the input.

This is, of course, unsecure.

As for creating files for a particular session, simplest is to create
the filename with a counter which is stepped per session instantiation,
and store this name in the Session itself, thus the correct files are
accessible via the name/password-Session mapping for each session access.

Finally, on servlet initialisation I create a watchdog thread that wakes
up every five minutes and examines every active Session (each session
records the time of its last access). Any session that hasn't been
touched in five minutes is presumed abandoned and so destroyed. In your
case, the Session itself will be told to kill itself, and it can delete
its files.

Signature

www.EdmundKirwan.com - Home of The Fractal Class Composition.

Download Fractality, free Java code analyzer:
www.EdmundKirwan.com/servlet/fractal/frac-page130.html

William Brogden - 12 Apr 2006 14:39 GMT
> Hi,
>
[quoted text clipped - 12 lines]
> Thanks for any help,
> Chris

Store all the File references in an object that implements
HttpSessionBindingListener and keep only that reference in the
session - when the session is invalidated for any reason, the
valueUnbound method will be called and you can proceed with
cleanup.

Bill
senges - 12 Apr 2006 19:16 GMT
thanks a lot,

... that's a nice way to do it really.

i just started implementing the HttpSessionListener interface which
allows for nice notification about session creation and destruction -
that works for me.

Chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.