Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaBean or Servlet?

 
Jacket lee
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic