aspose file tools*
The moose likes Servlets and the fly likes Listeners Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Listeners" Watch "Listeners" New topic
Author

Listeners

Dean Jones
Greenhorn

Joined: Dec 13, 2006
Posts: 23
I asked this question in the SCWCD forum, but it seems that nobody wants to answer it and I'm quite curious and being as this isn't directly related to the SCWCD forum, I figured I'd give it a shot in here.

I'm having a hard time figuring out when listeners are helpful. If you know when you add an attribute and you know you need to use the attribute that you added, why not just do the work then? Why do you need a listener?

Here is my example... If there is a better example that shows why to use a listener, by all means, let me know.

Let's say someone submits a form for a shopping cart, you have a doPost method and you handle them adding an item to their shopping cart (storing the stuff in the database or session data, whatever...) Then they move on to shopping and add more items, etc... Then they go to checkout. You have a servlet to handle checking the person out too... The checkout pull the session data, charges them checks them out... we're done.

At what point would there need to be a Listener to help with that application? Why does a class need to be sitting around waiting for another class to add a parameter or attribute??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60998
    
  65

Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place.

It looks like there are responses to your other post, so I'm not sure why you felt the need to say "nobody wants to answer". If you do feel that you started a topic in the wrong forum, ask a bartender or sheriff to move the post for you.

In this case, I've closed your previous post as the Servlets forum is a more appopriate location. But please do not cross-post in the future.
[ January 02, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

Listeners just give more flexibility. For example, can you tell how many users logged in your system? New security constrain doesn't allow you to enumerate active sessions, however you can do it in a listener. Another reason, if you did database programming and familiar with triggers, then you can consider listeners as trigger mechanism for servlets.


Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60998
    
  65

I use context listeners a lot more than session listeners.
Dean Jones
Greenhorn

Joined: Dec 13, 2006
Posts: 23
Bear,

Come on man, lighten up... The only person who wasted their time was you by posting that response. I had only one response in 2 days off of that last post and this forum is quite obviously a better place for that question. I can understand if I was going on every forum and posting the same question, but I had a good reason to post on two different forums being that I posted in the wrong place the first time (my fault, sorry).

But, lighten up a bit... It's a forum. I'm sure you like feeling all important by policing posts on an internet forum, but try to keep it under control and complain to the people that actually cause problems and litter up the forum.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60998
    
  65

Please do not feel unfairly picked upon. Your posts are no less, but no more, important than anyone else's, and must adhere to the same simple set of rules. I took my time to close your original topic and leave this one open because it seemed the most appropriate location for the discussion.

We feel that it's not too much to ask to limit your questions to one forum so that the volunteers that answer questions here do not spend time answering a question in one forum when it's already been answered in another.

If you would like to discuss JavaRanch policies please feel free to open a topic in the JavaRanch forum.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Listeners