• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How to use EL to get the value

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<%
request.setAttribute("vals",new Sring[]{"1","2","3","4"});
request.setAttribute("index","2");
%>
<%-- insert code here --%>
Which three EL expressions inserted at line 15,are valid and evaluate to "3"?(Choose three)

a)${vals.2}
b)${vals["2"]}
c)${vals.index}
d)${vals[index]}
e)${vals}[index]
f)${vals.(vals.index)}
g)${vals[vals[index-1]]}

I have seen this qestion in the mock exam
I have confusion on these types of question.
Could you explain this question clearly.
The implicit objects are param,paramValues,header,headerValues,pageContext,......
But here we are not using any implicit object.Please explain clearly
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
b)${vals["2"]}
evaluates to
third element in the StringArray attribute in the requestScope,which is 3.
Remember indexing start at 0.
d)${vals[index]}
evaluates to
Note that here no singleQuotes or Double Quotes around the index
Inside scriplet there is a statement
request.setAttribute("index","2");
So the expression simplifies to
${vals["2"]} which is again 3

g)${vals[vals[index-1]]}
evaluates to
${vals[vals["2"-1]]}
${vals[vals[1]]}
${vals[2]} which is again 3


EL will serach in all the four scopes in the order from
page,request,session,application.....
Here you put things in the request scope

If you want to be more specific
go for

${requestScope.vals[2]} or
${requestScope.vals['2']} or
${requestScope.vals["2"]}
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is more than implicit objects. In EL, you can access scoped variables via their name. When you do so, the variable will be searched in all scopes (page, request, session and application), and returned when found. (actually, the container will call PageContext.findAttribute) In your example, ${vals} will look for a variable called "vals" in the page scope, request scope, session scope and application scope. There is a "vals" attribute in the request scope, the one which has been set in a scriptlet, so ${vals} will return it. Therefore, ${vals} represents an array of String. Note that because "vals" is in the request, you could also access it via ${requestScope.vals}.
 
sukhavasi vasavi
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I got it.Thank you Verymuch
 
It's exactly the same and completely different as this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic