Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

scriptlet accsessing beans

 
Kanishka Ajwani
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A question from summary quiz 2 of www.examulator.com

Assuming that the JSTL tag is correctly configured what will happen when you attempt to compile and run the following JSP page?



Options:
A. Compile time error the JSTL tags cannot use EL expressions Incorrect
B. Compile time error the forEach tag has no varStatus attribute Incorrect
C. Compilation error JavaBeans cannot be manipulated within scriptlets Incorrect
D. Compilation and output of 1 Paul 2 Kathy 3 Frank

The correct answer mentioned is D. However I feel the answer should be C. Please correct me if I am wrong.

Thanks,
Kanishka
 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...However I feel the answer should be C...

Scriptlets have access to Java beans once they have declared in the page.
 
Kanishka Ajwani
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks Vijitha.

Scriptlets have access to Java beans once they have declared in the page.


Does that mean that scriptlets have access to Java beans only in page scope? Or java beans in all the scopes (request, session, application, page) can be accessed by scriptlets ?

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scriptlet variables have nothing at all to do with the scopes or scoped variables. So talking about "scope" with respect to scripting variables makes no sense.
 
Kanishka Ajwani
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear, so that concludes that scriptlets can access java beans declared in the JSP.

For eg,


will produce the output:
tadcaster tadcaster tadcaster


Have I got it right?

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But, of course, keep in mind that in the real world, scriptlets are no longer used in JSPs so the issue would never come up in real-world code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic