• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

JavaBeans in the context of Servlets

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
She'll be back. I'm just gonna wait here. With this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic