Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt regarding HttpSessionListener  RSS feed

 
anees ahamed
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I tried to work out an example given in http://www.roseindia.net/servlets/MySessionListener.shtml regarding HttpSessionListener.

As told in the example, I included the details of the servlet -- ServletSessionListener in web.xml.

But, when I run the servlet in browser, I get the output "The name is null" instead of "The name is bar".
I do not understand why this happens and why the attribute is not set.

Please help me to solve this.

Warm Regards,
Anees
 
Kuldeep Tewari
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you define your Listener in the start of your deployment descriptor?
 
Surya Kant
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should include "MySessionListener" as a listener in web.xml
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be extremely careful with articles at roseindia.net though: http://balusc.blogspot.com/2008/06/what-is-it-with-roseindia.html
 
anees ahamed
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
H,
Thanks for all your responses.

These are my xml details.


<servlet>
<servlet-name>MySessionListener</servlet-name>
<servlet-class>MySessionListener</servlet-class>
</servlet>
<servlet>
<servlet-name>ServletSessionListener</servlet-name>
<servlet-class>ServletSessionListener</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>MySessionListener</servlet-name>
<url-pattern>/MySessionListener</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ServletSessionListener</servlet-name>
<url-pattern>/ServletSessionListener</url-pattern>
</servlet-mapping>


I did not understand the two points which were posted as replies

1) You should include "MySessionListener" as a listener in web.xml
2) Did you define your Listener in the start of your deployment descriptor?

Can you please say what are these points?
 
Surya Kant
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out this url http://www.java2s.com/Tutorial/Java/0400__Servlet/ServletHttpSessionListener.htm
You will come to know.
If you are defining something as listener you should have that entry in web.xml
 
anees ahamed
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Surya,
I understood the concept and it worked.
So, its more like action listeners in swing rt? The methods sessionCreated(HttpSessionEvent sessionEvent), sessionDestroyed(HttpSessionEvent sessionEvent) etc. are only for notification purpose at the server side, am i rt?

We can set and remove atttributes as and when we like in any servlet class in the application, and the corresponding notifier methods will show the result in server.

Please correct me if I have gone wrong in any of the points above.
 
Surya Kant
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes absoluteky you are correct
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!