Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
JSP bean get property 
 

The code illustrate an example from JSP bean get property. In this example we define a package bean include a class Employees.

 

JSP bean get property

                          

The code illustrate an example from JSP bean get property. In this example we define a package bean include a class Employees. Inside the class we declared a String variable first Name, last Name and address. The get Address, first Name, last Name return you the value from a bean in JSP page. The JSP page uses bean get property and return the value stored in it.

<jsp:useBean>

  1. The <jsp:useBean> is used to instantiates a java bean component. 
  2. An attempt is made to locate and search an instance of the bean.

Attributes used in <jsp:useBean>

  1.  Id  - An attempt is made to search the bean with the scope .
  2.  class - This indicate package. class is used to give the reference of the bean class.

<jsp:get Property> -  

The <jsp:useBean>element contains a <jsp:getProperty> element that is used to retrieve the value stored in the getter method.

In order to run this program we need to place the file inside the Tomcat Home\WebApps\jsp bean get Property and start your tomcat. Once Tomcat is started ,type the url browser and run your application.

jsp bean getproperty.jsp

<html>
 <body>
  <h1>Get Value from bean</h1>
   <jsp:useBean id="emp" class="bean.Employees"/>
    <table>
     <tr>
      <td>First Name :
       <jsp:getProperty name="emp" property="firstName"/> 
      </td>
     </tr>
     <tr>
      <td>Last Name : 
       <jsp:getProperty name="emp" property="lastName"/> 
      </td>
      </tr>
     <tr>
      <td>Address :
       <jsp:getProperty name="emp" property="address"/> 
      </td>
     </tr>
    </table>
 </body>
</html>
 
Employees.java
package bean;
public class Employees {
    protected String firstName;
    protected String lastName;
    protected String address;
    public String getAddress() {
        address = "Delhi";
        return address;
    }
    public String getLastName() {
        lastName = "Singh";
        return lastName;
    }
    public String getFirstName() {
        firstName = "Komal";
        return firstName;
    }
}

Output of the program

Download Source code

                          

» View all related tutorials
Related Tags: c debugging exception error jsp ide orm process form debug io stack method format print get page trace vi trac

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.