jQuery in Action, 2nd edition*
The moose likes Servlets and the fly likes JavaBean or Servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JavaBean or Servlet?" Watch "JavaBean or Servlet?" New topic
Author

JavaBean or Servlet?

Jacket lee
Greenhorn

Joined: Oct 30, 2002
Posts: 6
Who can answer my question?
1.When is the best time to use JavaBean not Servlet?
2.When is the best time to use Servlet not JavaBean?
3.You can use Jsp to solve the question,why you also need to use Servlet?
Thanks first.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
1 & 2 Good design says your servlet should handle the communication interface and you should use JavaBeans (or other helper classes) to handle complex computing tasks, database lookup, etc. - In other words, don't try to do it all in one servlet class.
3. For one thing, you have to use servlet when working with binary data. Typically a servlet is the entry point for requests that may eventually be redirected to a JSP. JSP should not be loaded down with Java computations.
Bill
Rafael Prado
Ranch Hand

Joined: May 17, 2003
Posts: 33
Originally posted by William Brogden:
In other words, don't try to do it all in one servlet class.

Is it only for modularity purposes, or are there other aspects relevants of this statement?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
Reasons for using JavaBeans or other helper class:
1. You can debug the helper class outside the servlet container environment, thus saving time and frustation due to having to repeatedly reload the servlet.
2. Makes it easier to avoid Thread conflict problems.
3. Makers it easier to maintain and to explain to other programmers.
4. With good design, the helper class may prove useful in other projects.
Bill
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61449
    
  67

5. Makes it easier to unit test.
and on and on and on...
Listen to William for he is wise; it's just good practice!
bear
[ June 04, 2003: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaBean or Servlet?