• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ListenerTester

 
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ..


 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Alot!!!

Will see if it works for me..

Take care and have a great everning!

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic