• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in PageContext

 
Abhijit Das
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is the following two are line are same ?

pageContext.request.method

pageContext.getRrequest().getMethod()

 
swati bannore
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
provided request and method are the objects obtained from getRequest() and getMethod() resp.

Correct me if I am wrong..

 
cesar valencia
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not really, they are not the same.

${pageContext.request.method} would be the same as pageContext.getRequest().getMethod(); but both of them would cause compile time error in a jsp provided request is an instance of an implementation of javax.servlet.HttpServletRequest given that method is not really a method defined in that interface.
 
Rob Spoor
Sheriff
Pie
Posts: 20745
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpServletRequest.getMethod() does exist.
 
cesar valencia
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh yeah, that's right! Sorry, it eluded me as being "any given method" instead of a real method (get http method), otherwise my statement remains correct.
 
Abhijit Das
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i missed out one thing. These are used in EL.

${pageContext.request.method}

${pageContext.getRequest().getMethod()}
 
Finny Samuel
Greenhorn
Posts: 5
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${pageContext.request.method} will be correct in JSTL. But if you use expression language you should not use the method call, ${pageContext.request.method} will evaluate to pageContext.getRequest().<getMethod>(). [Replace <getMethod> by real method name]
As noted in previous posts, getMethod is not valid for javax.servlet.HttpServletRequest.
 
Rob Spoor
Sheriff
Pie
Posts: 20745
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finny Samuel wrote:As noted in previous posts, getMethod is not valid for javax.servlet.HttpServletRequest.

As noted in previous posts, yes it is.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic