aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes scriptlet accsessing beans 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 "scriptlet accsessing beans" Watch "scriptlet accsessing beans" New topic
Author

scriptlet accsessing beans

Kanishka Ajwani
Ranch Hand

Joined: Nov 30, 2009
Posts: 62
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

Joined: Mar 24, 2008
Posts: 3855

...However I feel the answer should be C...

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

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Kanishka Ajwani
Ranch Hand

Joined: Nov 30, 2009
Posts: 62

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

Joined: Jan 10, 2002
Posts: 61661
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kanishka Ajwani
Ranch Hand

Joined: Nov 30, 2009
Posts: 62
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

Joined: Jan 10, 2002
Posts: 61661
    
  67

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: scriptlet accsessing beans