This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL mock exam

 
vani venkat
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Givena JSP page with the following content
${request.noise}
${param.noise}
${requestScope.noise}
What will happen when the page is compiled and executed with the query string

index.jsp?noise=moo


Answer is moo.

Since there is no request implicit object in EL, why is it not giving compilation error for ${request.noise}
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the way EL works. When evaluating expr-a.identifier-b, EL first evaluates expr-a (in your example, request) into value-a. If value-a is null, it returns null. So it's over, it's going to evaluate identifier-b.
 
Harshana Dias
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:That's the way EL works. When evaluating expr-a.identifier-b, EL first evaluates expr-a (in your example, request) into value-a. If value-a is null, it returns null. So it's over, it's going to evaluate identifier-b.


Its kind of not understandable..will you please simplyfied it?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, with ${request.noise}, the container first tries to understand what "request" is. If it doesn't understand it, it returns null. It doesn't even try to understand what "noise" is. That's why there is no error when the page is accessed.

Check the spec at JSP.2.3.4 Operators "[]" and "."
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Harshana. Incase of ${request.noise}, the container chooses is there any request implicit object, since there is no 'request' object in EL. Also it checks, is there any attribute associated with name "request" like( pageContext.getAttribute("request"), request.getAttribute("request"), etc...). Since there is no such attribute found, so it returns 'null'. Then calling method through 'null' reference causes NullPointerException. EL will hides the exceptions. It will not show to the user.
 
vani venkat
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That makes it clear, thanks christopher and Chinmaya.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic