Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

EL question from Jdiscuss

 
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 ]
 
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.
 
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.
 
    Bookmark Topic Watch Topic
  • New Topic