File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using HttpSessionBindingListener interface

 
karim qazi
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am implementing HttpSessionBindingListener interface and I want to know when sessions are being created and dropped and then write something to a file when this event happens.
I thought all I had to do was implement this interface with the two methods valueBound() and valueUnbound() and sessions being created and dropped would automatically trigger these two methods to execute.
Any help would be appreciated.
Here is my code:
import java.io.*
public class Login extends User implements HttpSessionBindingListener {
private BufferedWriter log;

public Login() throws Exception {
super();
log = new BufferedWriter( new FileWriter("c:\\dvd_log.txt", true));
}

private void log(String data) throws IOException{
log.newLine(); // create new line to write to next time
log.write(data); // write input to file
log.flush();//clear buffer
}

public void valueBound(HttpSessionBindingEvent event){
try{
log("creating session...");
}catch(IOException e){
}
}

public void valueUnbound(HttpSessionBindingEvent event) {
try{
log("destroying session...");
}catch(IOException e){
}
}
}
[This message has been edited by karim qazi (edited March 27, 2001).]
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ACcording to the JavaDoc,
valueBound(HttpSessionBindingEvent event)
"Notifies the object that it is being bound to a session and identifies the session."
Apparently the only purpose is to notify an object when it is being bound (added?) to an HttpSession.
The opposite for
valueUnbound(HttpSessionBindingEvent event)
 
Sandeep Jain
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
HttpSessionBindingListener is used for the purpose of binding an object to the session .It basically notifies "the object that it is being bound to a session and identifies the session.
say for example .
Say u r implementing the connection pool urself and u do not depend on the webserver( not the application server) in this case when the session is invalidated then the code has to be written in such a way as to the connection should return back to the pool .
here u will write the code in valueUnbound and valueBound functions .

------------------
Sandeep Jain
 
karim qazi
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why doesent my code work when i create a new session?
it should write to a log file i set up when creating or destroying a session.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic