• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on EL

 
Ram Murthy
Ranch Hand
Posts: 91
  • 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

Choose at least one answer.
a. Output of moo moo moo
b. Output of moo moo null
c. output of null moo null
d. output of moo

The correct answer is d.

This is a question in the marcus green website.
I understand request.noise is invalid since EL is fogiving it ignored it. But shouldn't the output be <null moo moo>
or in other words, shouldn't {requestScope.noise} evaluate to moo

Please explain
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ram Murthy:
or in other words, shouldn't {requestScope.noise} evaluate to moo
Why would you think so?
[ September 01, 2007: Message edited by: Bear Bibeault ]
 
Ram Murthy
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because I thought requestScope is a valid EL implicit variable and and ${requestScope.noise} will act like request.getParameter(noise)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ram Murthy:
Because I thought requestScope is a valid EL implicit variable
It is.

and ${requestScope.noise} will act like request.getParameter(noise)
It will not. requestScope is a Map that represents the scoped variables in request scope. It has nothing to do with request parameters.
 
Jeff Horan
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are close, though.
Because I thought requestScope is a valid EL implicit variable and and ${requestScope.noise} will act like request.getParameter(noise)

It will act like request.getAttribute("noise"). And since you never saved it in the request object with setAttribute("noise", "moo"), it will be null.
 
Jeff Horan
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and this part, too...

since request.getAttribute("noise") returns null, then requestScope.noise returns nothing.
 
Ram Murthy
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gotcha..Thank you all
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic