Sylvain Roche wrote:
>
> Hi,
>
> I'm working on an online mail application. Everything works fine, but I
> have an architectural problem with attachements. In order to read them form
> the web page showing the message, I have to record them on the application
> server (from the mail server). Then the user can download or read them. No
> problem.
>
> Then I add sessions, as I want multiple users to read their mails
> simultanously. Each session creates its own directory on the server, to
> save its attachements.
>
> How can I delete the directory when a session has expired. I suppose this
> has to do with HttpSessionBindingListener, but I cannot figure how to use
> this with a directory, ie not an object in memory. Another way could be to
> implement a detroy method in a bean, which erases the directory linked to
> it when destroyed.
>
> Am I on a totaly wrong way ?
No, you're on the right track :-) You can create an instance of a class
that implements the HttpSessionBindingListener interface and give it
the directory name, e.g. a bean with a setDirName() method, and place
this object in the session. When the session is terminated, either by
an explicit call to invalidate() from the logic behind a logout page
or due to a timeout, the HttpSessionBindingListener valueUnbound() method
that you implemented in your bean is called by the container. In this
method you can get use the directory name given to the bean and remove
the directory using the standard Java File class methods.
<plug>
I describe more about how to use HttpSessionBindingListener objects
in chapter 15 of my JavaServer Pages book (O'Reilly):
<http://TheJSPBook.com/>
</plug>
Hans
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets