Jsp Tutorial Home

Jsp Home

JSP Resources

Community

Site

JavaBeans are reusable components. It represents a simple Java class with some properties. The bean properties are accessed by Getter and Setter method. They are used to separate Business logic from the Presentation logic. Internally, a bean is just an instance of a class. The JSP specification provides three basic tags for working with Beans :-


rn

jsp:useBean id="bean name" class="bean class" scope = "page | request | session |application "/>


rn
    rn
  • <jsp:setProperty name = "bean name" property = "someProperty" value = "someValue" />

  • rn
  • <jsp:getProperty name = "bean name" property = "someProperty"    />

  • rn

rn

Where bean name = the name that refers to the bean.
Bean class = name of the java class that defines the bean.
property = name of the property to be passed to the bean.
value = value of that particular property.


rn

The following is the explanation for the different scopes of a bean object in jsp:


rn
    rn
  1. Page scope:- This scope helps to keep the data available while the page is loading. Any object whose scope is defined as page scope will disappear as soon as the response is sent to the browser. The object with a page scope may be modified as often as desired within the particular page but the changes are lost as soon as the user moves away from the page. By default all beans have page scope.

  2. rn
  3. Request scope:- Any object created in the request scope will be available as long as the request object is valid. For example if the JSP page uses a <jsp:forward> tag, then the bean will be accessed in the forwarded page and if redirect is used then the bean is destroyed.

  4. rn
  5. 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 with a particular period of time the user spends at a site. Typically, this period is defined as all the hits a user makes to a website between starting and exiting his browser.

  6. rn
  7. Application Scope:- The bean associated with the application scope will be accessible to all the users and all the pages in the application. 

                    

Copyright © 2013 VisualBuilder. All rights reserved