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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Setting and getting JavaBean properties in JSP 
 

This example shows how to set and get properties of java bean class in jsp page.

 

Setting and getting JavaBean properties in JSP

                         

This example shows how to set and get properties of java bean class in jsp page. The important rules of setting and getting of properties are following:

  1. The set method name and property name must be same but with first letter in upper case and prefix with 'set'.
  2. The return type of the set method should be void and should take only one input parameter.
  3. The get method name and property name must be same but with first letter in upper case and prefix with 'get'.
  4. The return type of the get method can be String or any primitive type and should take no input parameter.

Source code of the JSPBean.java

package roseindia;
import java.io.*;

public class JSPBean {

  private String developer = "Sandeep";
  private String company = "Roseindia";
  private String city = "Delhi";

  public void setDeveloper(String developer) {
    developer = developer;
  }
  public String getDeveloper() {
    return developer;
  }

  public void setCompany(String company) {
    company = company;
  }
  public String getCompany() {
    return company;
  }
    
  public void setCity(String city) {
    city = city;
  }
  public String getCity() {
    return city;
  }  
}

useBean.jsp

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

<html>
        <body>
                <jsp:useBean id="b" class="roseindia.JSPBean"/>

                <jsp:setProperty name="b" property="developer" />
                Developer = 
                <jsp:getProperty name="b" property="developer"/><br/>

                <jsp:setProperty name="b" property="company" />
                Company = 
                <jsp:getProperty name="b" property="company"/><br/>

                <jsp:setProperty name="b" property="city" />
                City = 
                <jsp:getProperty name="b" property="city"/><br/>

        </body>
</html>

</jsp:root>

Compile this program on the command prompt: 

C:\apache-tomcat-6.0.16\webapps\ServletExample\WEB-INF\classes>javac -d . JSPBean.java

Start the tomcat and run the jsp file on browser as given url: http://localhost:8080/ServletExample/jsp/useBean.jsp  then the output will be displayed as below:

Download Source Code

                         

» View all related tutorials
Related Tags: java html c web jsp dynamic static script servlet sed ip page tag this log tar close js start technology

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.