JSP and JSTL Tutorials - Tutorial Addendum - Using JavaBean Classes

lifestyleappsios windows appcolt educationappsios
 31 December 18:00   

    



    



    



    

This affiliate explains:

    



        

  • How to amount a JavaBean into JSP pages and dispense its properties.

        



  •     

  • Compilation issues of using JavaBean classes in bearding packages.

        



  •     

  • Setting and accepting JavaBean s properties.

        



  •     

  • Using JavaBean s as Java altar in scripting elements.

        



  •     

  • Using Java altar as JavaBean s.

        



  •     

  • How to brace the JavaBean altar loaded in memory.

        



  •     



    



    



    

The "jsp:useBean" Activity Elements

    



    

jsp:useBean: A JSP activity aspect that endless a JavaBean item into the JSP page.

    

 

    

<jsp:useBean id="object_name">

    



    



    

where "object_name" is the name of the item to be created, and "class_name" is the

    

class name of the JavaBean chic from which the item will be instantiated.

    



    

Once a bean item is loaded into the page, you can use two additional activity elements to

    

manipulate it.

    

 

    

<jsp:setProperty name="obj" property="prop_name" value="prop_value"/>

    

<jsp:getProperty name="obj" property="prop_name"/>

    



    



    

The "setProperty" activity will set a new amount to the defined acreage of the specified

    

bean object. The "getProperty" activity will get the accepted amount of the defined property

    

of the defined bean object. This amount will be adapted into a string

    



    

Once a bean item is loaded into the page, it can be acclimated in additional

    

scripting elements in the aforementioned JSP page.

    



    

Here is my first JavaBean , CacheBean.java:

    

 

    

/**

    

* CacheBean.java

    

* Absorb (c) 2002 by Dr. Yang. All rights reserved.

    

*/

    

public chic CacheBean {

    

clandestine Cord argument = "null";

    

accessible Cord getText() {

    

acknowledgment text;

    

}

    

accessible abandoned setText(String text) {

    

this.text = text;

    

}

    

accessible Cord getInfo() {

    

acknowledgment "My JavaBean - Adaptation 1.00"

    

}

    

}

    



    



    

Here is a simple JSP page to appearance you how to use JavaBean , UseBean.jsp:

    

 

    

<?xml version="1.0"?>

    

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

    

<!-- UseBean.jsp

    

Absorb (c) 2002 by Dr. Yang

    

-->

    

<html><body>

    

<jsp:directive.page import="CacheBean"/>

    

<jsp:useBean id="b">

    

<jsp:setProperty name="b" property="text" value="Hello world!"/>

    

Property from my Bean:

    

<jsp:getProperty name="b" property="text"/>

    

<br/>

    

Info from my Bean:

    

<jsp:expression>b.getInfo()</jsp:expression>

    

</body></html>

    

</jsp:root>

    



    



    

Then I aggregate CacheBean.java with JDK 1.3.1, and affected CacheBean.class

    

to localjakarta-tomcat-4.1.18webapps
ootweb-infclasses.

    

Here is what I got by requesting UseBean.jsp from IE:

    

 

    

Property from my Bean: Accost world!

    

Info from my Bean: My JavaBean - Adaptation 1.00

    



    



    

Note that CacheBean chic needs to be alien into the JSP page. The chic file

    

needs to be affected to the .web-infclasses directory.

    

(Continued on next part...)

    



    

 


Tags: action, class, classes, property, elements, value, notes, public, string, tutorial, tutorials, object

 javabean, object, usebean, property, cachebean, value, action, class, public, string, version, classes, specified, getproperty, elements, setproperty, objects, javabeans, loaded, , < jsp, jsp page, usebean jsp, cachebean java, javabean classes, jsp usebean, bean object, obj property prop, property prop name, jsp getproperty name, jsp setproperty name, 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