Java
  Home arrow Java arrow Page 3 - Overview of Java Web Technologies, Par...
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

Overview of Java Web Technologies, Part 2
By: McGraw-Hill/Osborne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2004-03-03

    Table of Contents:
  • Overview of Java Web Technologies, Part 2
  • Sun's Solution
  • JSP and JavaBeans
  • Calling a Bean from a JSP Page
  • Accessing Bean Properties
  • Custom Tags
  • Developing and Using Custom Tag Libraries
  • Writing a Tag Handler
  • Writing and Using Tags
  • Model 2 Architecture

  • 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
     
    IBM developerWorks
     
    ADVERTISEMENT

    AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th -1:00PM EST. Register Today!

    Overview of Java Web Technologies, Part 2 - JSP and JavaBeans


    (Page 3 of 10 )


    Although you can easily write JSP pages by interweaving HTML tags and Java code, there are at least two disadvantages to this approach. First, the resulting page lacks readability. Second, there is no separation of the presentation and business rule implementation. To write a JSP page this way, a JSP author must master both Java and page design. This is difficult because not many people are conversant in both graphic design and Java programming.

    A separation of labor between a graphic designer and a Java programmer is needed to expedite the development of JSP applications. This is possible through the use of JavaBeans. In this approach, the Java programmer writes and compiles JavaBeans that incorporate all the functionality needed in an application. While the programmer is doing this, the graphic designer can work with the page design. When the JavaBeans are ready, the page designer uses tags similar to HTML to call methods and properties of the beans from the JSP page.

    In fact, using beans is a common practice in JSP application development. This approach is popular because using JavaBeans introduces reusability. Rather than building your own piece of code, you can simply use what other people have written. For example, you can purchase a bean for file upload and start uploading files within 30 seconds.

    NOTE:
    When you are designing a JavaBean for your JSP page, reusability and modularity are of utmost importance. Therefore, it is uncommon to use a bean to send HTML tags to the Web browser, because this makes the bean customized for that page. If you need to send HTML tags customized for a page, you can use custom tags instead, as explained later in this chapter.

    Really, a JavaBean is just a Java class. You do not need to extend any base class or implement any interface to create a JavaBean. To be a bean, however, a Java class must follow certain rules specified by the JavaBeans specification. For example, the bean class must have a no-argument constructor. If a Java class does not contain a constructor, the compiler will create a no-argument constructor.

    Setting and Getting JavaBean Properties

    Optionally, a bean can have a public method that can be used to set the value of a property. This method is called a setter method or a mutator. The method does not return any value, and its name starts with set, followed by the name of the property. A setter method has the following signature:

     
    public void setPropertyName (PropertyType value

    For example, the setter method for the property name operand must be named setOperand. Notice that the letter case for the property name is different. A property name starts with a lowercase letter, but the name of the setter uses an uppercase letter after set.

    Optionally, a bean can also have a public method that can be called to obtain the value of a property. This method is called a getter method or a accessor, and its return type is the same as the property type. Its name must begin with get, followed by the name of the property. A getter method has the following signature:

     
    public propertyType getPropertyName(); 

    For example, the getter method for the property named operand is getOperand. As with the setter method syntax, the property name begins with an uppercase letter within the getter method syntax.

    Both setter and getter methods are known as access methods. In JSP, the jsp:getProperty and jsp:setProperty action elements are used to invoke a getter and a setter method, respectively. You can call these methods the same way you call an ordinary method, as described in the “Accessing Bean Properties” section later in this chapter.

    Buy this book now!Remember: This is part two of the first chapter of JavaServer Faces Programming, by Budi Kurniawan (McGraw-Hill/Osborne, ISBN 0-07-222983). Stay tuned for more chapters of developer books from McGraw-Hill/Osborne.
    Buy this book!

    More Java Articles
    More By McGraw-Hill/Osborne


     

       

    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 6 hosted by Hostway