• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

HttpSessionListener

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am facing a problem in using HttpSessionListener.I am using Tomcat 4.0.
I am trying to execute examples given in Manning book. I get the following error when I start server.
Apache Tomcat/4.0.1
ERROR reading java.io.ByteArrayInputStream@e74d75fd
I mentioned listener in web.xml is as follows :
<listener>
<listener-class>util.SessionCounter</listener-class>
</listener>
Please help me in understanding Listener class usage.
I am planning to give my SCWCD exam soon.
Thanks,
Ram
 
Ram prakash
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is DTD declaration in my web.xml
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
is this right DTD version I am using.
Thanks,
Ram
 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ram
Might help if you post the source code? Also, I understand that the Exam Study Kit source code has been updated for Tomcat 4.1.n. See here for more details.
 
Ram prakash
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my code for Listener class :
package util;
import javax.servlet.http.*;

public class SessionCounter implements HttpSessionListener {

private static int activeSessions = 0;
public void sessionCreated (HttpSessionEvent evt) {
activeSessions++;
System.out.println("No. of active sessions on : "+new java.util.Date()+" : "+activeSessions);
}
public void sessionDestroyed(HttpSessionEvent evt) {
activeSessions--;
}
}
web.xml is given in previous post.
Thanks,
Ram
 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ram
Modify the DTD in your deployment descriptor to:

Note the 2.3 (not 2.2). I tried it using your supplied code and it worked ok.
 
Ram prakash
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,
I changed the DTD header as suggested by you.
I get the following error when I start Tomcat server.
Apache Tomcat/4.0.1
ERROR reading java.io.ByteArrayInputStream@d17a195e
At Line 14 /web-app/servlet-mapping/
I removed listener tag in web.xml , still I get
the same error.
Is this because of my Tomcat version?
do I need to update my server version.If yes, where can I get next version of server.
Please help me.
Thanks for all your advice.
Ram
 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ram
I just shooting at anything here, but the error you are getting included a reference to a servlet-mapping.

At Line 14 /web-app/servlet-mapping/


Perhaps there's a clue there. Can you post your complete web.xml file? Use the CODE button below to make it more readable
Mark.
 
Ram prakash
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,
Here is my web.xml code



Thanks,
Ram
 
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this ...
 
I'm a lumberjack and I'm okay, I sleep all night and work all day. Lumberjack ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic