Win a copy of AWS Security this week in the Cloud/Virtualization 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Why is EL invalid in this example?

 
Ranch Hand
Posts: 46
Oracle Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to create a JSP that generates some JavaScript code to populate
an array of strings used on the client-side. Which JSP code snippet will create this array?

[code=java]
A. MY_ARRAY = new Array();
<% for ( int i = 0; i < serverArray.length; i++ ) {
MY_ARRAY[<%= i %>] = '<%= serverArray[i] %>';
} %>
B. MY_ARRAY = new Array();
<% for ( int i = 0; i < serverArray.length; i++ ) {
MY_ARRAY[${i}] = '${serverArray[i]}';
} %>
C. MY_ARRAY = new Array();
<% for ( int i = 0; i < serverArray.length; i++ ) { %>
MY_ARRAY[<%= i %>] = '<%= serverArray[i] %>';
<% } %>
D. MY_ARRAY = new Array();
<% for ( int i = 0; i < serverArray.length; i++ ) { %>
MY_ARRAY[${i}] = '${serverArray[i]}';
<% } %>

[/code]

Answer: C

I understand that A and B are not correct, but can someone please clarify why is D incorrect?

Urgent.
Thanks
Dishi
 
Sheriff
Posts: 4869
317
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dishi Jain wrote:Urgent.


Only for you. Not for anyone else here. You should read this --> EaseUp

Why don't you explain to us what it is about option A and B that makes you believe them to be incorrect.
Then explain what it is about C that leads you to believe it is correct.
Then have a look at D at tell us what you see. What is it about D that makes you unsure whether it's incorrect?
 
Dishi Jain
Ranch Hand
Posts: 46
Oracle Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Tim,

Seems you took it so hard on yourself

Ok, so to answer your questions,

A - incorrect - scriptlets cannot have expressions inside them
B - incorrect - scriptlets cannot have ELs inside them

C is correct as per the other forums. And yes it is. Actually while answering your questions i noticed that D is an assignment task, without any scriptlets..I noticed the ';'

Sorry for the inconvenience caused..
However I would still want you to confirm that my assumption is correct

PS-I wrote urgent because I have my ocwcd on coming Monday!!

Thanks,
Dishi
 
Tim Cooke
Sheriff
Posts: 4869
317
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say the reason option D is incorrect is because of a scoping issue between Scriptlets and EL. The variables i and serverArray[] are defined in a Scriptlet, but then access is attempted through EL, which won't work because scriptlet scope is not the same as EL scope. If you tried it you would probably just get an empty string for that placeholder in your JavaScript presentation.
 
Dishi Jain
Ranch Hand
Posts: 46
Oracle Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yes..I dint think about scopes at all. It can be seen that way too, makes it more clear for me.
I appreciate your inputs.

Thanks
 
Tim Cooke
Sheriff
Posts: 4869
317
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
Best of luck with your exam on Monday. I'm sure we'll see you back in the Certification Results forum hopefully with good news.
 
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic