Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaBeans in the context of Servlets  RSS feed

 
Simon Harvey
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I am trying to understand the use of beans in the context of servlets. Firstly I'm going to write down my definition of a bean and f someone could correct my interpretation of it then that would be really great:
I think the implementation of a bean is really simple. It is just a typical class that is used for storing related information. In theat regard its methods are simply of the for setXXX() and getXXX();
Thats its only function. Is that correct? Can a java bean have any other sorts of methods or does that exclude it from being a bean? Should logic be carried out icside the bean, or again, does that invalidate it?
The other thing is a bean in the context of a servlet. I've been told that you should encapsulate any related information in a javabean. Then youcan pass it around methods and even servlets if you want to use sessions. Am I right in thinking that this is what a javabean is for - passing round information in a nicely packaged way.
Am I also right in thinking that as long as pass the java bean around via method parameters and dont assign the bean globally, that the java bean data wont become corrupt because only the correct request will ever be accessing the information?
Thanks guys and take care
Regards
Simon Harvey
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For details on the whole JavaBean picture, you can go to Sun's Definition Page for the conventions of the JavaBean Component Architecture. It is a lot more complicated than the way we typically use beans in servlets.
You have correctly deduced that in the context of servlets and JSP, JavaBeans are pretty simple, however, their use extends beyond simple storage. Including calculations, database access and other functions is no problem with a bean.
On your final point, typically a bean is used in the context of a single session or maybe a single request, but nothing prevents you from using one in a global context.
Bill
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!