• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference between servlets and javabeans  RSS feed

 
Simon Harvey
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
I'm just getting started making a little website for some practice with jsp and servlets etc.
What I'm wondering about is what the difference is between servlets and javabeans. They seem to be fairly similar. For example I think i could use either as a means of connecting cleanly to a database. Would that be right?
I maybe have some idea of the difference, but maybe iv just made it up because it seems sensible to me. Im wondering if servlets are more based on logic and controlling what the application dows, whereas javabeans are sort of like a mechanism to store application state.
For example, I was thinking that I would access a database once in a while to get the details of all those users that were currently authorised on the site - I would store those details in a javabean. That way I would only need to look at the bean rather than doing an expensive read from the database. I was thinking that I would use servlets to control that process.
The only problem with that though is that it seems to make the session mechanism redundant, because the session stores application state as well right?
I really hope someone can settle this for me. I sort of see whats going on but my ideas could do with a bit of tidying.
Many thanks everyone
Simon
Oh, one last thing. When I'm making javabeans, do i strictly need to worry about making it in that bean box thing and considering whether or not the bean will be accessible via a clever ide?
Thanks again everyone. Take care y'all
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets and JavaBeans are completely different concepts. The servlet API provides for servicing Internet requests, typically from client browsers but not limited to that.
JavaBeans are a "component" architecture for encapsulating functionality. A typical use would be a bean used by a servlet to handle database inquiries, but bean architecture is used in lots of places.
Sessions are the servlet mechanism for storing objects related to a particular user, these objects may or may not be beans.
Beans used to create user interfaces (with your "clever ide") have more stringent requirements. Beans used in servlets and JSP are typically simpler.
Bill
 
Simon Harvey
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill,
Well, perhaps you could clear this up for me.
I'm coming at this from a jsp point of view - If i wanted to take the code for accessing a database out of the jsp page, i could put the code in either a servlet, OR a jb.
Which should i use and why. Now the difference i seem to be seeing is that Servlets can respond to web page requests, whereas javabeans respond to method calls.
It also seems that servlets are also given fairly important jobs like controllers or redirectors and authorisers
Thanks for your help again
Simon
Which should i use in the previous scenario?
Thanks again
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!