my dog learned polymorphism*
The moose likes Servlets and the fly likes In which package should be a Listener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "In which package should be a Listener" Watch "In which package should be a Listener" New topic
Author

In which package should be a Listener

Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
Hello..
I am using MVC for my web-app.
I have two packages:
(1)myPackage.web : Package for Controller classes (Servlets)
(2)myPackage.model : Package for Model classes (Helper classes)

Now I want to add a ServletContextListener class in my app.
In which package should I put it?

Thanks in advance..


Hakuna Matata!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Is it part of the model?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
Originally posted by Bear Bibeault:
Is it part of the model?


The Listener is used to get Data Source Name from context-init-parameters and to get a Connection using that Data Source Name, which can be used by Model classes afterwards
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Your model should be compeltely independent of the user interface. In other words, if you chose to put a Swing UI on your application, would the listener class still be a useful part of the model?
Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
Sorry, Bear
I didn't get your answer..
Can you elaborate it?
Thanks in advance...
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Bear Bibeault:
Your model should be completely independent of the user interface. ...


In your case the user interface (UI) is a servlet application.
ServletListeners are part of the servlet spec and part of the javax.servlet. API.

Would your model package be independent of the UI if it contained classes that need to import javax.servlet classes?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
Don't get me started about those stupid light bulbs.
 
subject: In which package should be a Listener