File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes ListenerTester Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "ListenerTester" Watch "ListenerTester" New topic
Author

ListenerTester

Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
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

The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
udaykumar maddigatla
Ranch Hand

Joined: Feb 03, 2009
Posts: 69
In your dog class add this implements HttpSessionBindingListener.



SCJP 5.0(84%), SCWCD 5.0(97%), SCDJWS 5.0(98%)
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
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

Joined: Jul 06, 2008
Posts: 85
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.




SCDJWS 5.0, SCBCD 5.0, SCWCD 5.0, SCJP 5.0
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
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

Joined: Nov 05, 2007
Posts: 661
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

Joined: Jul 27, 2006
Posts: 57
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


Studying ...
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
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

Joined: Jul 27, 2006
Posts: 57
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

Joined: Nov 05, 2007
Posts: 661
Thanks Alot!!!

Will see if it works for me..

Take care and have a great everning!

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ListenerTester
 
Similar Threads
[Solved]Need some clarification about <jsp:useBean/> standard action.
Cannot get HttpSessionBindingListener method valueBound to trigger
about System.out.printnln()
Java Cast with Multiple Arguments
Cannot find symbol :Class Dog