Java
  Home arrow Java arrow Page 6 - The JSP Files (part 7): Bugs, Beans An...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

The JSP Files (part 7): Bugs, Beans And Banks
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2001-04-18

    Table of Contents:
  • The JSP Files (part 7): Bugs, Beans And Banks
  • Bugathon
  • Exceptionally Clever
  • Bad News
  • You Throw(), I'll Catch
  • Bean Bag
  • Turning Up The Heat

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    The JSP Files (part 7): Bugs, Beans And Banks - Bean Bag


    (Page 6 of 7 )

    One of the most compelling things about JSP, from a development point of view, is that it allows for the easy integration of existing JavaBeans into JSP scripts (for those of you not in the loop, JavaBeans is object-oriented technology which allows developers to build reusable Java components or applications). The advantages of this are obvious: an organization which has already made an investment in JavaBeans technology can leverage off it to quickly reuse existing code modules, at minimal time and cost.

    We're not going to get into the nitty-gritty of building a JavaBean here - there are innumerable tutorials out there on the topic, including a good one from Sun Microsystems at http://java.sun.com/docs/books/tutorial/javabeans/. Instead, we're simply going to touch briefly on the JSP constructs which allow you to import a Bean into your JSP script, set Bean properties and access Bean methods.

    JavaBeans are brought into a JSP script by means of the action, which creates an instance of the Bean and identifies the scope of its activities.

    The following code snippet creates an instance of the Bean "iceCream", identifies it with the unique ID "vanilla" and defines its scope to be limited to the "page".

    <jsp:useBean id="vanilla" scope="page" class="iceCream"> </jsp:useBean>

    The "scope" attribute above defines the extent of the Bean's influence. For example, "scope=page" implies that the instance will remain active for the current page, while "scope=session" indicates that the instance will remain available throughout the session.{mospagebreak title=Taking It To The Bank} Closely related to <jsp:useBean> is <jsp:setProperty>, typically used to set Bean properties; these properties may be set explicitly, or on the basis of parameters available in the Request object (you remember this, don't you?)

    The following code snippet uses the <jsp:setProperty> action to assign the value "7683" to the Bean property "accountBalance". Note that the <jsp:setProperty> action references an instance of a previously-defined Bean, named "account"

    <jsp:useBean id="account" scope="page" class="Bank"> <jsp:setProperty name="account" property="accountBalance" value="7683" /> </jsp:useBean>

    If you'd like to set instance properties on the basis of data in the Request object - say, form values - you could use

    <jsp:setProperty name="account" property="*" />

    and JSP would automatically iterate through the Request object, match parameter names with available Bean properties, and assign values appropriately.

    More Java Articles
    More By Vikram Vaswani and Harish Kamath, (c) Melonfire


     

       

    JAVA ARTICLES

    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway