• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do Javabeans work?

 
Linda Thomas
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been working with beans and I love them but I've gotten some issues lately and so I want to fully understand what is going on with the beans and how they work.

When I create a bean on my JSP page where is the bean? Is it hanging in RAM? How reliable is the information? How long does the bean exist? I have it set to session scope and I access the bean in the header file so for each and every page I access that bean. Is it possible to lose the information somehow? (besides the session timing out when the user hasn't used it in 30 mins)

How does a bean compare to a session variable? They seem to have the same function to me, both being persistant information I can access at any page of my project, but beans are more powerful. Session variables are objects and require casting to insert integers.

Should I set the bean as application scope?
ClientBean newBean = ( ClientBean )session.getAttribute( "tempclientbean" ); Is how I am accessing the bean in a class file where we do all our stored procedures and other database features. I tried to switch to the application scope but that session.getAttribute won't work. I think I need to access application beans differently but I don't know.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Setting a bean to session scope has (effectively) the same effect as saying session.setAttribute(somekey, something).
You can loose them, but only if either the session itself disappears (which means a timeout or you invalidated it) or if you delete it deliberately from the session (I omitted the case where the server goes down, you probably have bigger problems when that happens).

Application scope sets something to be available to ALL requests in the application, so across sessions.
Changes made for one session will thus be seen by all sessions. Think of it as a static member of a class.

Most effective in my experience are session and request scoped parameters.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!