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



Home Jsp Simple-jsp-example Using [] operator of EL with an Array

Related Tutorials


 
 

Share on Google+Share on Google+

Using [] operator of EL with an Array

Advertisement
This page discusses - Using [] operator of EL with an Array

Using [ ] operator of EL with an Array

        

EL expressions are always used within curly braces, and prefixed with a dollar($) sign and $(expression). The first named variable in the expression is either an implicit object or an attribute stored in one of the the four scopes i.e. page, request, session, or application. The [] operator is much more powerful than the dot, because it lets you access Map key or a bean property name as well as the access to arrays and Lists.

An array is a type of container which can hold a fixed number of values of a single type. Array is a collection of similar data types. It means if you have declared an array as string then it can only store the string values. The length of an array is established when an array is created. After creation of the length, its length can't be changed.  The [] operator of EL provides us to access the variables of the arrays which dot(.) operator doesn't provide.  By using the dot(.) operator we can only access the properties of bean and map.

The code of the program is given below:

 

<% String[] name = {"Hello", "you", "are", "using", "[] operator", "in", "EL"};
request.setAttribute("name", name);
%>
<body>
<center>
<table>
<tr><td><b>The first element is an array is :</td></b> <td><b>${name[0]}</tr></td></b><br>
<tr><td><b>The second element is an array is : </td></b> <td><b>${name["1"]}</tr></td></b><br>
<tr><td><b>The third element is an array is : </td></b> <td><b>${name["2"]}</tr></td></b><br>
<tr><td><b>The fourth element is an array is : </td></b> <td><b>${name["3"]}</tr></td></b><br>
<tr><td><b>The fifth element is an array is : </td></b> <td><b>${name["4"]}</tr></td></b><br>
<tr><td><b>The sixth element is an array is : </td></b> <td><b>${name["5"]}</tr></td></b><br>
<tr><td><b>The seventh element is an array is : </td></b> <td><b>${name["6"]}</tr></td></b><br>
</table>
</center>
</body>

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: April 18, 2011

Related Tutorials

Discuss: Using [] operator of EL with an Array  

Post your Comment


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