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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
JSP bean set property 
 

In this Tutorial we want to describe you a code that help in describing an example from JSP bean set property.

 

JSP bean set property

                          

In this Tutorial we want to describe you a code that help in describing an example from JSP bean set property. The code include a package bean , we have a class Employees. The employee class include a string variable first name, last name and address. Inside the class we have a setter and getter method.

  1. set XXX ( ): This method hold the value of the parameter  by the implementor of interface.
  2. get  XXX( ): This method retrieve the value of the parameter set in the setXXX ( ) method.

The JSP page uses this getter and setter method.

  1. <jsp:useBean> -   

    The  < jsp:use Bean> instantiate a bean class and locate a bean class with specific scope and name.

                      

    • id - A id variable is used to identify the bean in the scope .
    • class -The class is represented as Package. class and instantiate a bean from class. The class should be public 
    • scope -This  describe you the scope of the bean in which it exists.  

     

  2. <jsp:set Property>This is used to set the value of one or more properties of bean using setter method. The value of the name must match with the Id.
  3. <jsp:get Property>This is used to return the bean property value using property getter method in bean package.

For running this application we need to save the jsp bean getproperty.jsp in Tomcat/wepapps/.jsp.The required url is typed in the browser and the JSP page will be displayed.

jsp bean getproperty.jsp

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
 <body>
  <h1>Get Value from bean</h1>
    <jsp:useBean id="emp" class="bean.Employees" scope="page" />
        
    <jsp:setProperty name="emp" property="firstName" value="Komal Singh"/>
    <jsp:setProperty name="emp" property="lastName" value="Choudhary"/>
    <jsp:setProperty name="emp" property="adddress" value="Delhi"/>
        
     <table>
      <tr>
       <td>First Name</td>
       <td> : </td>
       <td> <jsp:getProperty name="emp" property="firstName"/> </td>
      </tr>
      <tr>
       <td>Last Name</td>
       <td> : </td>
       <td> <jsp:getProperty name="emp" property="lastName"/> </td>
      </tr>
      <tr>
       <td>Address</td>
       <td> : </td>
       <td> <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 void setAddress(String address) {
        this.address = address;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getAddress() {
        return address;
    }
    public String getLastName() {
        return lastName;
    }
    public String getFirstName() {
        return firstName;
    }
}

Output of the program

Download Source code

                          

» View all related tutorials
Related Tags: c exception error jsp io count page using invoke js handle if to ci counter e directive can pe ce

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.