• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple question

 
revup triv
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is JavaBeans same as Servlets? Can you have all your JAvaBeans code sit in Servlets? And this way elliminate the JavaBeans?
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaBeans are objects that hold data and provide "getter and setter" methods. Servlets are objects that reside on web servers and are called when requests are made. One of these cannot possibly replace the other.
 
revup triv
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually to be more specific.. I have bunch of DB calls made from JavaBeans which is nothing but simple Java methods. So my questions is why can't I put them in servlet wherever they r required & get rid of JavaBeans... what is wrong in it?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ever heard of code reuse?
You're bound to need that same code at some other point sooner rather than later. Are you just going to copy and paste from one servlet to another?
What if you need to make a change and forget to apply it everywhere?
 
m bhramaresh
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
triv,
if i got u correctly, u just want to put your methods which are in beans into the servlets right.
you can do that.
but actually after MVC came into the picture, front end part in jsp, servlet as a controller and beans for methods, specially for DB calls.
you can write the methods in servlets, but better to write in beans...
it will be systematic.
what bothers you to write methods in beans??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic