aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HttpSessionListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HttpSessionListener" Watch "HttpSessionListener" New topic
Author

HttpSessionListener

Ram prakash
Greenhorn

Joined: Dec 20, 2002
Posts: 11
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

Joined: Dec 20, 2002
Posts: 11
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

Joined: Feb 14, 2001
Posts: 285
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

Joined: Dec 20, 2002
Posts: 11
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

Joined: Feb 14, 2001
Posts: 285
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

Joined: Dec 20, 2002
Posts: 11
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

Joined: Feb 14, 2001
Posts: 285
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

Joined: Dec 20, 2002
Posts: 11
Hi Mark,
Here is my web.xml code



Thanks,
Ram
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
Try this ...


"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpSessionListener