File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL

 
Sharma Anjali
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic