• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ListenerTester

 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I ws just trying out the listener class mentioned in HFSJ pg 171 and I got the result as expected.
I modified the Dog class to check the sequence of how it runs , However , didnot get the expected results.

I am still hazy with the concepts and trying to put the all the bits together.( I dont know if it's my slow understanding or whether I'll understand things better as i move ahead!)

Anyway,
My modified code is :


I have a feeling I am missing something here. Just not sure what it is ...

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However , didnot get the expected results.

Those, like me, who don't have the book will find it difficult to help you. If you could explain your problem a bit more. What kind of listener are you referring to ? Post the listener, and the web.xml if necessary. Also tell us what you were expecting.
 
udaykumar maddigatla
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your dog class add this implements HttpSessionBindingListener.


 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Web.xml file :



And My Servlet is :




My Listener Class is :



I got the output :
test context attributes set by listener
Dog's breed is : Great Dane


The result I was expectiing was when i added
System.out.println("In the Dog constructor");
System.out.println("In the getBreed()");
in the Dog class

I expected that that it displays "in the Dog constructor" when Dog object is created in MyServletContextListener and
"in the getBreed()" is displayed when getBreed() is called by the Servlet.
That way i can see the sequence of actions taking place.

Again, I may be asking something pretty silly .. everythign is still hazy in my head and I am not sure how things are working n why we are using it..
But hoping things clear out as i study ahead.


 
Vinay Nath
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you check the server's log, it should get printed there...


Nabila Mohammad wrote:My Web.xml file :



And My Servlet is :




My Listener Class is :



I got the output :
test context attributes set by listener
Dog's breed is : Great Dane


The result I was expectiing was when i added
System.out.println("In the Dog constructor");
System.out.println("In the getBreed()");
in the Dog class

I expected that that it displays "in the Dog constructor" when Dog object is created in MyServletContextListener and
"in the getBreed()" is displayed when getBreed() is called by the Servlet.
That way i can see the sequence of actions taking place.

Again, I may be asking something pretty silly .. everythign is still hazy in my head and I am not sure how things are working n why we are using it..
But hoping things clear out as i study ahead.


 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure how to read the Servler's Log..

But from what I could make out in the Catalina file in the logs directory there ws nothing of that sort displayed there.
As a matter of fact I couldnt find any of my files name there...
Am i reading the log right?

 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is every one a silent spectator of this forum or doesnt any body know what i am talking about....

I was hoping this to be as responsive n as encouraging as SCJP section ..


 
Mateus Lucio
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ... I'm not sure if this info will help you ... anyway ...

I think your doubt is why your System.out.println("") are not been printed, well it's because your server doesn't know a standard output. If you are using eclipse and tomcat, you should see your messages in eclipse console.

I suggest you add a logging tool in your projects, even for tests, or use ServletContext.log("").

I lost sometime with this issue either, but i didn't thought that losing more time on that was worthy for my purposes, so I just gave up on that.
If you want to search for "configuring standard output in tomcat" or something like it!

[]'s
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mateus !

Atleast some one replied.

This forum seems kind of slow as far as response is concenered....

Any way can you help me out on how to do this.. I am stilll a little new with the programming concept..

I suggest you add a logging tool in your projects, even for tests, or use ServletContext.log("").




 
Mateus Lucio
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure ... that one is easier to me.

If you just want a simple log mechanism to study and running some examples, you can use the log method of the ServletContext object, you can get a reference to it in any servlet or listener class like:



if you're in a servlet class just do this in doGet, doPost, or any other method:


If you want a real development/production logging tool I suggest log4j (http://logging.apache.org/site/binindex.html)
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Alot!!!

Will see if it works for me..

Take care and have a great everning!

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic