Home Jsp Simple-jsp-example EL and Complex Java Beans
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

EL and Complex Java Beans

Advertisement
EL means the expression language , it makes it possible to easily access application data stored in JavaBeans components. The jsp expression language allows a page author to access a bean using simple syntax such as $(name).

EL and Complex Java Beans

        

EL means the expression language , it makes it possible to easily access application data stored in JavaBeans components. The jsp expression language allows a page author to access a bean using simple syntax such as $(name).  Before JSP 2.0, we could  use only  a scriptlet, JSP expression, or a custom tag to include server state in the jsp page output. Using scripting in jsp all the time makes the program difficult to understand as it grows bigger in size.  Expression Language (EL) was first introduced in JSTL 1.0.  EL provides us a way to access the java code. EL is such a language which is liked by java programmers as well as by those who are not programmers like designers.

Java Beans: They are platform- independent component and usable software programs which you can use develop and assemble easily to create complex applications. JavaBean are also known as beans. Beans are called dynamic as they can be easily customized or changed.

In this example we have created one bean class consisting only of setter and getter method. These setter and getter method will be used in the jsp. To set the value in a jsp page use <jsp:setProperty> standard tag. We are using the EL to retrieve the value of the bean.

The code of the of the program is given below:

 

public class ComplexJavaBeans{
private String name;
private int age;
private String address;
private int phone;
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setAge(int age){
this.age = age;
}
public int getAge(){
return age;
}
public void setAddress(String address){
this.address = address;
}
public String getAddress(){
return address;
}
public void setPhone(int phone){
this.phone = phone;
}
public int getPhone(){
return phone;
}
}

 

<jsp:useBean id="person" class="Mybean.ComplexJavaBeans" scope="request" />
<jsp:setProperty name = "person" property = "name" value = "James"/>
<jsp:setProperty name = "person" property = "age" value = "35"/>
<jsp:setProperty name = "person" property = "address" value = "007,Colony No.2"/>
<jsp:setProperty name = "person" property = "phone" value = "1234567890"/>
<html>
<body>
  <h1>EL and Complex JavaBeans</h1>
  <table border="1">
  <tr>
  <td>${person.name}</td>
  <td>${person.age}</td>
  <td>${person.address}</td>
  <td>${person.phone}</td>
  </tr>  
  </table>
  </body>
</html>

The output of the program is given below:

Download this example.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 12, 2008

Related Tutorials

Ask Questions?    Discuss: EL and Complex Java Beans   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com