JSP and JSTL Tutorials - Tutorial Addendum - Using JavaBean Classes

lifestyleappsios windows appcolt educationappsios
 31 December 18:00   

    



    



    

(Continued from antecedent part...)

    



    

Note that:

    



        

  • Property names are case sensitive. Acreage name "Author" can not be mapped to

        

    "getAuthor" method.

        



  •     

  • Two set methods after any one demography Cord as ascribe constant blazon is giving

        

    me problem to set "total".

        



  •     

  • Two set methods with one demography Cord as ascribe constant blazon is ok. Achievement

        

    line 5 is the prove.

        



  •     



    



    



    

Using JavaBeans as Altar in Scripting Elements

    



    

As I mentioned in the antecedent section, JavaBean is just a accustomed Java item with

    

some appropriate method. Already a JavaBean is created, we should be able to use it as

    

Java item in any scripting elements.

    



    

Here is a sample page to appearance you how to use a JavaBean as a Java object. It is using

    

the aforementioned JavaBean class, .DemoBean, as the antecedent section.

    

 

    

<?xml version="1.0"?>

    

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2">

    

<!-- BeanAsObject.jsp

    

Absorb (c) 2003 by Dr. Yang

    

-->

    

<html><body>

    

<jsp:useBean id="b">

    

<jsp:setProperty name="b" property="author" value="Someone"/>

    

Line 11: columnist =

    

<jsp:expression>b.getAuthor()</jsp:expression><br/>

    

<jsp:scriptlet><![CDATA[b.setTotal(10);]]></jsp:scriptlet>

    

Line 12: absolute =

    

<jsp:getProperty name="b" property="total"/><br/>

    

<jsp:scriptlet><![CDATA[b.setSize(15);]]></jsp:scriptlet>

    

Line 13: admeasurement =

    

<jsp:getProperty name="b" property="size"/><br/>

    

Line 14: admeasurement =

    

<jsp:scriptlet><![CDATA[out.println(b.getSize());]]></jsp:scriptlet>

    

<br/>

    

<jsp:scriptlet><![CDATA[

    

Item o = pageContext.findAttribute("b");

    

Cord s = ((.DemoBean)o).getSize();

    

out.println("Line 15: admeasurement = "+s);

    

]]></jsp:scriptlet><br/>

    

</body></html>

    

</jsp:root>

    



    



    

Open this JSP page with IE, you will get:

    

 

    

Line 11: columnist = Someone

    

Line 12: absolute = int: 10

    

Line 13: admeasurement = int: 15

    

Line 14: admeasurement = int: 15

    

Line 15: admeasurement = int: 15

    



    



    

Note that:

    



        

  • Line 11 tells us that we can use an announcement aspect to get the acreage value.

        



  •     

  • Line 12 tells us that if we use scriptlet element, we can alarm a specific

        

    version of setTotal method. Bethink setProperty bootless on "total" in the antecedent

        

    example.

        



  •     

  • Line 15 tells us that we aswell retrieve the item aback from pageContext, because

        

    useBean aspect abundance the JavaBean item in pageContext.

        



  •     



    

(Continued on next part...)

    



    

 


Tags: property, method, author, notes, string, tutorial, tells, tutorials, object

 scriptlet, javabean, object, property, total, cdata, author, previous, tells, element, pagecontext, method, string, expression, , < jsp, jsp scriptlet, scriptlet <, > <, < cdata, size int, size <, input parameter type, jsp scriptlet line, jsp getproperty name, one taking string, notes using javabean, tutorials tutorial notes, tutorial notes using, jstl tutorials tutorial,

Share JSP and JSTL Tutorials - Tutorial Addendum - Using JavaBean Classes:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  jsp