Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cleaning Diskfiles on session time-out  RSS feed

 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
My JSP pages would create some temporary disk files and i want to delete them when the session times out. Please tell me how to achieve this. Will implementing the HttpSessionListener or HttpSessionBindingListener would be useful?
Thanks is advance
Sudharsan G
 
Val Pecaoco
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sudharsan G:
Hi!
... or HttpSessionBindingListener would be useful?
Thanks is advance
Sudharsan G


Yes. You do the cleanup stuff inside the valueUnbound() method.
Ex Animo Java!
-- Val
 
georgejk
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai
I think you can delete a file using the code:
<%@page import="java.io.*"%>
<%
String textFromTextArea = request.getParameter("message");
if(textFromTextArea!=null){
String path = "c:\\file.txt";
File file = new File(path);
Writer writer = new BufferedWriter(new FileWriter(file));
writer.write(textFromTextArea);
writer.flush();
writer.close();
file.delete();
}
%>
Just try and let me know
George
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi George!
I dont want to delete a file from a JSP Page. I need to delete some files when a session times out. This code may be put inside
sessionDestroyed(SessionEvent se) method of HttpSessionListener or
valueUnbound(SessionBindingEvent sbe) method of HttpSessionBindingListener. I couldn't understand when this valueUnbound() method is called? And if i'm implementing the HttpSessionListener i need to add an entry into the web.xml file. I'm not sure what is the entry to be created and in which web.xml file.
regards
Sudharsan G
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!