Java beans

Solo disponible en BuenasTareas
  • Páginas : 4 (789 palabras )
  • Descarga(s) : 0
  • Publicado : 26 de abril de 2011
Leer documento completo
Vista previa del texto
Java Beans

Java Beans are reusable components. They are used to separate Business logic from the Presentation logic. Internally, a bean is just an instance of a class.

 JSP’s provide threebasic tags for working with Beans.  

• bean name = the name that refers to the bean.
• bean class = name of the java class that defines the bean. 

• id = the name of the bean asspecified in the useBean tag.
• property = name of the property to be passed to the bean.
• value = value of that particular property .

An variant for this tag is the property attribute can bereplaced by an “ * ”. What this does is that it accepts all the form parameters and thus reduces the need for writing multiple setProperty tags. The only consideration is that the form parameter namesshould be the same as that of the bean property names.

• Here the property is the name of the property whose value is to be obtained from the bean.

Bean scopes:

These defines the rangeand lifespan of the bean. The different options are :

Page scope :

Any object whose scope is the page will disappear as soon as the current page finishes generating. The object with a page scopemay be modified as often as desired within the particular page but the changes are lost as soon as the page exists. By default all beans have page scope.

Request scope :

Any objects created inthe request scope will be available as long as the request object is. For example if the JSP page uses an jsp:forward tag, then the bean should be applicable in the forwarded JSP also, if the scopedefined is of Request scope.

The Session scope :

In JSP terms, the data associated with the user has session scope. A session does not correspond directly to the user; rather, it corresponds witha particular period of time the user spends at a site. Typically, this period is defined as all the visits a user makes to a site between starting and existing his browser.

The BEAN structure :...
tracking img