• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help on HttpSessionListener  RSS feed

 
HanMing Low
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I've created a class, MyListener, that implements HttpSessionListener and in the sessionCreated method I do a simple
System.out.println("Session Created");
Then, in the web.xml I have the following,
<listener>
<listener-class>MyListener</listener-class>
</listener>
And, I have a simple servlet, MyServlet, that simply return a simple html page.
All this is within a web app.
However, in both Weblogic and Tomcat, both doesn't print the message when I access MyServlet.
(I understand Tomcat will not print in the command windows, but Weblogic should)
Though MyServlet return the html page correctly.
In what scenario will the sessionCreated be called, or how do I configure the listener so that the sessionCreated is called when I access MyServlet.
Thanks for any reply.
Cheers.

Han Ming
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your servlet create a session using request.getSession()?
 
HanMing Low
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mathew,
Thanks for the answer.
Yup, it the cause and it solved the problem.
I'm just curious on another question.
Isn't a session suppose to begin when a browser start to browse a page on the site or is it suppose that the server must specifically start a session to begin the session?
Thanks again.
Cheers.

Han Ming
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A HttpSession begins when you tell it to begin, either by calling HttpServletRequest.getSession or by browsing to JSP with session="true" set.
[ September 28, 2002: Message edited by: Chris Mathews ]
 
HanMing Low
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,
Thanks for your reply.
I've a better understanding of it now.
Cheers.

Han Ming
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!