• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why HttpSessionListener gets invoked?

 
Tiffiny Yang
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel strange when I launch a simple hello.jsp without any session created, I can see the my HttpSessionListener gets invoked with messages like below in the console.
MySessionListener: session is created
MySessionListener: session is Destroyed

-- here's how I view my simple hello.jsp
http://localhost:8080/myWeb/JSP/hello.jsp

The hello.jsp file only has a line of code: Hello

---MySessionListener.java
package coreservlets.listeners;
import javax.servlet.http.*;
public class MySessionListener implements HttpSessionListener
{
public void sessionCreated(HttpSessionEvent se) {System.out.println("MySessionListener: session is created.");}
public void sessionDestroyed(HttpSessionEvent se) {System.out.println("MySessionListener: session is Destroyed.");}
}
--
MySessionListener class is registered in web.xml with no problem.

Can anybody tell me why?

Thanks in advance.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your JSP page have an explicit



included? If it doesn't, then a session will be opened automatically, as per the JSP spec.
[ April 11, 2007: Message edited by: Ulf Dittmer ]
 
Tiffiny Yang
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I did not include that.

You're right. By default, session is default to true.

Thanks for pointing it out.

Tiffny
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!