aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Unable to understand the solution on EL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Unable to understand the solution on EL" Watch "Unable to understand the solution on EL" New topic
Author

Unable to understand the solution on EL

Padma priya Gururajan
Ranch Hand

Joined: Oct 05, 2006
Posts: 434
Hi,
I am unable to understand the following question:
Given the servlet code below, figure out what would print.
java.util.ArrayList nums = new java.util.ArrayList();
nums.add("1");
nums.add("2");
nums.add("3");
request.setAttribute("numbers",nums);
String[] favoriteMusic = {"zero 7","Tahiti 80","BT","Frou Frou"};
request.setAttribute("musicList",favoriteMusic);

1. ${musicList[numbers[0]]}
2. ${musicList[numbers[0]+1]}
3. ${musicList[numbers["2"]]}
4. ${musicList[numbers[numbers[1]]]}


Padma priya N.G.
Be the change you want to be - Mahatma Gandhi
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You should read JSP.2.3.4 Operators "[]" and "." from the JSP specification. Basically, using brackets with an List will cause List.get(int index) to be called. So numbers[0] is the same as nums.get(0);
There are a few coercion rules explained in the spec. It would be easier to refer to it first.


[My Blog]
All roads lead to JavaRanch
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
I'll give you a hint, Try evaluating the numbers[whatever] expression first, make the substitution if needed and continue to evaluate if you are not finished
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
tell me what you think each of them resolves to and I will help you. If I cannot see that you have tried by yourself then I will wait until I can see that you have tried to reason it out.
Padma priya Gururajan
Ranch Hand

Joined: Oct 05, 2006
Posts: 434
Hi,
Thanks.
With regards,
Padma priya N.G.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to understand the solution on EL