JavaBeans and JSP - PowerPoint PPT Presentation

About This Presentation
Title:

JavaBeans and JSP

Description:

JavaBeans and JSP JavaBeans The Java component technology originally intended for the creation and management of pluggable GUI components; Java s answer to ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 8
Provided by: Parikshit
Category:

less

Transcript and Presenter's Notes

Title: JavaBeans and JSP


1
JavaBeans and JSP
2
JavaBeans
  • The Java component technology
  • originally intended for the creation and
    management of pluggable GUI components Javas
    answer to Visual Basics VBX/OCXs
  • becoming more popular for encapsulating business
    logic for server-side applications (especially
    Java Server Pages
  • many Java GUI Development tools have been
    modified to allow application development of
    server-side applications (Visual Café, Jbuilder,
    VisualAge for Java) along with the development
    tools being delivered with application servers
    (SilverStream, BEA Weblogic)
  • A JavaBean is nothing more than a class that
    maintains some state data (called properties) and
    follows a certain set of coding conventions.
    Along with certain Java runtime support
    (reflection and introspection) JavaBeans can be
    easily added to and maintained by most of the
    Java GUI Development Tools .
  • A bean encapsulates data about one entity

3
API requires that
  • Must implement java.io.Serializable or
    java.io.Externalizable
  • A Java bean must be in a package
  • Beans must be able to support their own
    persistence
  • this allows the bean to be saved and restored
    consistently
  • provide a no-arguments constructor
  • provides a single way for the Bean to be
    instantiated
  • insures consistent bean creation and
    initialization
  • private properties must have corresponding
    get/set methods that follow the appropriate
    naming patterns
  • each piece of state data to be exposed is called
    a property
  • a property is either read-only (has a set),
    write-only (has a get)or read-write (has both)
  • a property is case-sensitive and starts with a
    lower-case letter
  • made public via accessor and mutators (gets and
    sets)
  • accessor method names must start with get
    have no arguments
  • for property int color the accessor would be
    getColor() (note cap C)
  • mutator method names must start with set and
    return void
  • for property fuelCapacity the mutator would be
    setFuelCapacity()

4
jspuseBean Tag
  • jspuseBean does the following
  • If the object is found within the specified scope
    it is retrieved and assigned to the object
  • if not found it is instantiated
  • if newly instantiated it executes the code
    specified in the body ( one or more
    jspsetProperty tags or a scriptlet)
  • if newly instantiated it is saved into the scope
    via setAttribute( ) method
  • jspuseBean also makes the bean visible to the
    JSP there may be other objects in the context
    that were put there by other JSPs or servlets
    jspuseBean can make them visible to the current
    JSP

5
jspuseBean Tag (more)
  • Attributes
  • id
  • scope
  • class
  • beanName
  • type
  • ltjspuseBean id today class java.util.Dategt
  • instantiates a bean called today of class
    java.util.Date( )
  • ltjspuseBean id count class
    java.lang.Integer type java.lang.Numbergt
  • essentially does Number count count new
    Integer( )
  • ltjspuseBean id count class lt
    request.getParameter(beanName)gt type
    Number /gt
  • essentiallt does Number count count
    java.beans.Beans.instantiate(request.getParameter(
    beanName))

6
jspuseBean Tag (more)
  • Scope of a Java Bean- Four Scopes Available
  • Page
  • available only within the JSP page and is
    destroyed when the page has finished generating
    its output for the request
  • Request
  • destroyed when the response is sent
  • Session
  • destroyed when the session is destroyed
  • Application
  • destroyed when the web application is destroyed.

7
jspuseBean Tag (more)
  • In general the syntax is

ltjspuseBean id name scope page request
session application /gt
Write a Comment
User Comments (0)
About PowerShow.com