This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes isELIgnored attribute 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 "isELIgnored attribute" Watch "isELIgnored attribute" New topic
Author

isELIgnored attribute

Amruth Puppala
Ranch Hand

Joined: Jul 14, 2008
Posts: 295
Source jdiscuss mock
Consider the following JSP page:


<%@page isELIgnored='false'%>
<html>
<body>
<h1>
<% request.setAttribute("pageContext", "pagecontext"); %>
pageContext = ${pageContext}
</h1>
</body>
</html>


Assuming that both - scripting and EL are allowed in the page, what will it print for ${pageContext}?

Select 1 correct option.

A. It will cause a translation error.
B. It will print the string "pagecontext".
C. It will print nothing.
D. It will throw an exception at request time.
E. None of these



correct answer is E.
Explanation: Since, pageContext is also the name of an implicit object, the expression ${pageContext} will evaulate to that object. Therefore, it is not recommended to use names of impicit objects as regular attributes.

But my answer is D.
Please do provide you answer also.


SCJP 5 |SCWCD 5| Started thinking about Web Services ?
Kelahcim Kela
Greenhorn

Joined: Aug 17, 2007
Posts: 29
As far as I recall, toString() method is called in that case. Thus you will get something similar to:

pageContext = org.apache.jasper.runtime.PageContextImpl@5c7734

Cheers
deepa raj
Ranch Hand

Joined: Jul 25, 2008
Posts: 124


as for as EL concerned ,

{implicitObject.property} or {attribute.property}

EL first check whether this is a implicit Object , if yes evaluate with implicit object property or this is page/request/session/application Attribute , if yes evaluate with that attributes property.

so , pageContext is a Implicit Object .so it is printing the Object name.

and also, while setting the attribute key value is just a string , key value of the setAttribute method is not validated by the container.so it wont throw exception like pageContext is a already defined implicit Object.

Hope this helps.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Chintu sirivennela:

correct answer is E.
Explanation: Since, pageContext is also the name of an implicit object, the expression ${pageContext} will evaulate to that object. Therefore, it is not recommended to use names of impicit objects as regular attributes.



i tried answare is correct only
Amruth Puppala
Ranch Hand

Joined: Jul 14, 2008
Posts: 295
Lucid explanation deepa raj ..

So to access the pageContext attribute
${pageContext.request.pageContext} ?
or
${requestScope.pageContext} ? which one will work..


[ August 19, 2008: Message edited by: Chintu sirivennela ]
[ August 19, 2008: Message edited by: Chintu sirivennela ]
deepa raj
Ranch Hand

Joined: Jul 25, 2008
Posts: 124


Runtime Exception .because , HttpServletRequest( ${pageContext.request})doesnt have page Context as one property.

${requestScope.pageContext}

will retrieve the value set by you.
Amruth Puppala
Ranch Hand

Joined: Jul 14, 2008
Posts: 295
thanks ..

Deepa see your private message
Milind Patil
Greenhorn

Joined: Oct 19, 2003
Posts: 26
I tried to run this on tomcat server, Just wanted to share with you guys,

<% request.setAttribute("pageContext", "My Page Context"); %>
pageContext = ${pageContext}<br/>
pageContext.request = ${pageContext.request}<br/>
requestScope.pageContext = ${requestScope.pageContext}<br/>
//pageContext.request.pageContext = ${pageContext.request.pageContext}<br/> - Getting ServletException

OutPut:
pageContext = org.apache.jasper.runtime.PageContextImpl@d3c65d
pageContext.request = org.apache.catalina.connector.RequestFacade@1578aab
requestScope.pageContext = My Page Context

[ August 20, 2008: Message edited by: Milind Patil ]

Milind B. Patil - SCJP-1.4, SCWCD-5.0, SCBCD-5.0
 
GeeCON Prague 2014
 
subject: isELIgnored attribute