Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL question from Jdiscuss

 
kapil munjal
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Consider the following code appearing in a JSP file:

<%
request.setAttribute("names", new String[]{ "A", "B", "C" } );
request.setAttribute("index", "1");
%>
<h1><!-- insert code here --></h1>


Which of the following statements will print B in inserted in the above JSP page?


Options

Select 3 correct options.

1 ${names.1}
2 ${names[1]}
3 ${names.index}
4 ${names[index]}
5 ${names.$index}
6 ${names[$index]}


This question is taken from jdiscuss site and it gives 3 answers.

Answer - 2,3 and 4.

My confusion is 3rd option ${names.index}. I think it should not work as names is an array and '.' operator doesn't work with Arrays and List.

I have no idea why Enthuware termed it as correct.

Could someone help me out with this.
[ July 21, 2005: Message edited by: kapil munjal ]
 
Kedar Dravid
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, that's probably a bug in the JDiscuss mock exam suite.
 
kapil munjal
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kedar.
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if it had been a Map, ${names.index} wouldn't have worked since it translates to ${names["index"]} instead of ${names[index]}.

-Yuriy
 
kapil munjal
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats right Yuriy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic