Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • 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: 42969
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic