• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Usage of ${pageContext.request}

 
Swapna James
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I understand that {$requestScope.foo} is not equal to {$pageContext.request.foo}. Can anybody tell me under what circumstances that we will be using {$pageContext.XXX}. I am confused with these EL Implicit Objects.

Thanks,

Swapna
 
Sandeep Bhandari
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Swapna James:
Hi Guys,

I understand that {$requestScope.foo} is not equal to {$pageContext.request.foo}. Can anybody tell me under what circumstances that we will be using {$pageContext.XXX}. I am confused with these EL Implicit Objects.

Thanks,

Swapna


pageContext is very different from rest of implict EL variables. requestScope will make you available the attributes added to the request scope which we used to add using request.addAttribute() method.

But pageContext.request refers to the request object itself that is for the web it is HttpServletRequest

Please note the different between request object and request scope in which we add attributes.
 
Swapna James
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that {$pageContext.request} is an instance of HttpRequest, but can you tell me where we can use it?
 
Sandeep Bhandari
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Swapna James:
I understand that {$pageContext.request} is an instance of HttpRequest, but can you tell me where we can use it?


The usage is same as HttpServlet object. Though it is almost never required because you have requestScope and cookies available to you already as separate variable. But since pagecontext contains the request object, its available to you.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pageContext may play good role in EL and Tag Handler
 
Rodrigo Vieira
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sandeep Bhandari, I think you made a mistake, the method to put attributes in the request is setAttribute(), not addAttribute().
These attributes are available to the requestScope implicit variable. The diference between this variable and pageContext.request is because the second one have acess to other methods of HttpServletRequest while requestScope is limited to acess attributes.
 
Joy Mukherjee
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Examples:

The request's URI (obtained from HttpServletRequest):

${pageContext.request.requestURI}
 
Baddy Davay
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and the the main difference would be the getter method .The HttpServletRequest has the getAttribute(name) to get the attribute value.But the requestScope is a map which stores the attribute as name value pairs so you can access the values as ${requestScope.name} but you cannot do ${pageContext.request.name} . remember the java bean getter method you require for using EL does not take any parameters inside.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic