Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

isELIgnored attribute

 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • 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.
 
Kelahcim Kela
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • 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
 
deepa raj
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • 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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
thanks ..

Deepa see your private message
 
Milind Patil
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic