Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSessionListener

 
Ram prakash
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Mark Howard
Ranch Hand
Posts: 285
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
Here is my web.xml code



Thanks,
Ram
 
R K Singh
Ranch Hand
Posts: 5382
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this ...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic