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

Request Parameter -Regarding

 
vinod balaji
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mock exam Question:
${request.noise} #1
${param.noise} #2
${requestScope.noise}#3
What will happen when the page is compiled and executed with the query string

index.jsp?noise=moo

What is the Output and which one will work.
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
output is #1 moo #2 #3
${param.noise} will execute.
 
vinod balaji
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks
 
Firas Zuriekat
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


"noise" in this case is a request attribute and not a parameter. Therefore, the output of ${requestScope.noise} is nothing. This is because "noise" as a parameter is not defined.

Please let me know if I am correct?
 
Abhijeet Mahule
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Firas,
The line: index.jsp?noise=moo
indicates that index.jsp is being invoked with a parameter whose name is "noise" and value is "moo".
Now this parameter value can be retrieved in the index.jsp page by using the EL expression ${param.noise}. Note that "param" is the implicit EL variable that is used to retieve the value of parameter being sent to the jsp.

${requestScope.noise} refers to the value of attribute object named "noise" that is added to the request scope(request.setAttribute(String name,Object obj)) and is retrievable using the implicit EL variable "requestScope".

The expression ${request.noise} is invalid since there is no implicit EL variable named "request".

Hence the answer is: #1 moo #2 #3
Note that "noise" is a parameter not a request attribute.

Hope this is clear


Stay connected, Remain beautiful,
Abhijeet
SCJP 1.4, SCWCD 1.4

[ December 18, 2006: Message edited by: Abhijeet Mahule ]
[ December 18, 2006: Message edited by: Abhijeet Mahule ]
 
Firas Zuriekat
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, this clears many things. If one could remember that EL almost never throws an Exception or Error (it's very forgiving), then the output here will be nothing when ${request.noise} is used (request doesn't exist in EL).

So that's why we get this result even when using this non-existent "request".



EL is cool
[ December 18, 2006: Message edited by: Firas Zuriekat ]
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good revision for me
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic