Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Jsp Simple-jsp-example Use of dot(.) operator in EL

Related Tutorials


 
 

Share on Google+Share on Google+

Use of dot(.) operator in EL

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).

Use of dot(.) operator in EL

        

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.

We use dot(.) operator within EL to access properties of bean and map values. For example in the EL ${useOfDotOperator.name, the left hand side variable will be a map value or a bean. The thing to the right of the dot operator must be a Map key or a bean property and the thing on the right must follow normal java naming rules for identifiers for example it must start with a letter, underscore( _ ), or a $ sign, it can't be a java keyword.

The code of the program is given below:

 

<html>
<head>
<title>Use Of Dot operator in EL</title>
</head>
<body>
<form method = "get" action = "UseOfDotOperatorInEL.jsp">
Enter your name    = <input type = "text" name = "name"><br>
Enter your address = <input type = "text" name = "address"><br>
<input type = "submit" name = "submit" value = "submit">
</form>
</body>
</html>

 

package Mybean;
public class UseOfDotOperatorInEL{
	private String name;
	private String address;
	public void setName(String name){
		this.name = name;
	}
	public String getName(){
		return name;
	}
	public void setAddress(String address){
		this.address = address;
	}
	public String getAddress(){
		return address;
	}
}

 

<jsp:useBean id="useOfDotOperator" class="Mybean.UseOfDotOperatorInEL" scope="request" />
<jsp:setProperty name = "useOfDotOperator" property = "name" value = "${param.name}"/>
<jsp:setProperty name = "useOfDotOperator" property = "address" value = "${param.address}"/>
<html>
<body>
  <h1>Use of Dot operator in EL</h1>
  <table border="2">
  <tr>
  <td>${useOfDotOperator.name}</td>
  <td>${useOfDotOperator.address}</td>
  </tr>  
  </table>
  </body>
</html>

 

The output of the program is given below:

Download this example.

Advertisements

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 11, 2008

Related Tutorials

Discuss: Use of dot(.) operator in EL   View All Comments

Post your Comment


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