This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes EL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "EL" Watch "EL" New topic
Author

EL

Sharma Anjali
Ranch Hand

Joined: Feb 22, 2005
Posts: 63
The above code does not display anything
<html>
<body>
<% String [] favFood = {"Ice cream", "Chocolate", "pizza"}; %>
Food: ${favFood["0"]}
</body>
</html>


But if I make the following changes it works fine

<html>
<body>
<% String [] favFood = {"Ice cream", "Chocolate", "pizza"};
request.setAttribute("favFood", favFood);
%>
Food: ${favFood["0"]}
</body>
</html>


Why do I have to set the array as an attribute? Why can't I access it on the same page without setting it an an attribute.
Nitish Bahadur
Ranch Hand

Joined: Aug 25, 2003
Posts: 118
The EL needs to find the variable(and its value) in some namespace. The namespace it looks at are page, request, session, and application. Declaring a scripting variable does not add the variable to any namespace. Hence you have to use setAttribute.
 
Don't get me started about those stupid light bulbs.
 
subject: EL
 
Similar Threads
Problem in compiling Jsp
JSTL not working
WA #1.....word association
Doubt in EL?
List Best Inventions