Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EL expressions  RSS feed

 
Sophie Angela
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<% int[] num={11,22};
request.setAttribute("attr",num); %>

${requestScope["attr"][0]}
/-------------------------------------/

how does this EL expression evaluvates?

requestScope.attr[0]

requestScope.attr evaluavtes to num object.so the above expression will be evaluvated as ${num[0]} ..is it true?
If so can the object be directly used in a EL expression ..instead of a Attribute name?
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${requestScope.attr[0]} and ${requestScope["attr"][0]} both will evaluate to ${num[0]} and will print "11". Yes you can use ${attr[0]} directly and the output will be same but you can't use ${num[0]} because the EL searches the used attribute in different scopes starting from page then request,session and application, so "attr" will be found in request scope whereas there is no attribute in any scope by the name of "num".
 
Sophie Angela
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!