• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PageContext methods in EL?

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

How can I access the methods of the request interface like getMethod() and so on using EL?? One such example to access the request method in EL is like this
${pageContext.request.method}, I want to access other methods as well the same way?? How to do this??
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the pageContext object as a java bean, which means that you can call on any method that has the form getXyz() by reading the xyz property of the bean: ${pageContext.xyz}.

The same applies to the request object you can retrieve from pageContext, so then:
${pageContext.request.method}
is equivalent to:
<%= pageContext.getRequest().getMethod() %>

Note: the difference in capitalization is important.

[ March 27, 2007: Message edited by: Sergio Tridente ]
[ March 27, 2007: Message edited by: Sergio Tridente ]
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sergio,

Thanks for the reply. Like you said,

${pageContext.request.method}
is equivalent to:
<%= pageContext.getRequest().getMethod() %>

What is the way if I want to get the request url like

<%= pageContext.getRequest().getRequestURI() %> ...How can I do this usinf EL?
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any idea guys??
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jothi Shankar Kumar Sankararaj:
What is the way if I want to get the request url like

<%= pageContext.getRequest().getRequestURI() %> ...How can I do this usinf EL?


You should use: ${pageContext.request.requestURI}
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sergio,

Thank you very much for the reply. From where I can know about all the properties like this???
 
Clifton Eaton
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jothi Shankar Kumar Sankararaj:
sergio,

What is the way if I want to get the request url like

<%= pageContext.getRequest().getRequestURI() %> ...How can I do this usinf EL?


I believe this expression should be this:

<%= ((HttpServletRequest)pageContext.getRequest()).getRequestURI() %>

(pageContext.getRequest() returns ServletRequest but its actually an HttpServletRequest)
[ March 27, 2007: Message edited by: Clifton Eaton ]
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see the API for request object...
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Clifton Eaton:


I believe this expression should be this:

<%= ((HttpServletRequest)pageContext.getRequest()).getRequestURI() %>

(pageContext.getRequest() returns ServletRequest but its actually an HttpServletRequest)


You are right. Thank you.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, where can I find the rest of the properties guys?? Please let me know!
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the JSP specification, there are listed at "JSP.2.2.3 Implicit Objects"
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks satou!
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But Satou,

I can find only this from the specs,

${pageContext.request.requestURI} The request's URI (obtained from HttpServletRequest)
${sessionScope.profile} The session-scoped attribute named profile
(null if not found)
${param.productId} The String value of the productId
parameter, or null if not found
${paramValues.productId} The String[] containing all values of the
productId parameter, or null if not found

I want to know how we can access each method in the HttpServletRequest interface using EL?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can access all those which have a proper getter method, via pageContext.request. getRequestURI() is one, getQueryString() is another. Have look at HttpServletRequest and look for getter methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic