• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

isELIgnored attribute

 
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks ..

Deepa see your private message
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic