• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

difference in forwarding using PageContext.forward and RequestDispatcher.forward

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI

Please excuse me if these are dump questions.


Please tell me whats the difference in forwarding using PageContext.forward and RequestDispatcher.forward?

 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
RequestDispacher,forward method taking request & response as parameter & while getting request dispatcher we are giving path for forward resource,


and while forwarding through PageContext we are giving resource path to parameter of forward method,



we can use RequestDispacher in Servlet as well as Jsp
but PageContext we can use in only jsp.



 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you shail .

I tried to use PageContext.forward("") , but its giving me a error while compiling

"non-static method forward(java.lang.String)cannot be referenced from a static context"



Can please anyone tell me what is the meaning of that error.
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,



Have a look of PageContext API.

We dont have any static method forward within PageContext Class, so the error.

Rather it should be pageContext.forward("/resource.jsp");
Assuming you are using within a JSP.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mohammed

Rather it should be pageContext.forward("/resource.jsp");



Is there any difference in what i specified and what you suggested ??



And i am using this inside the servlet , and not in jsp
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


pageContext is object (which is created by the JSP container) where as PageContext is Class.
 
Mohamed Inayath
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Pavan wrote:Thanks Mohammed

Rather it should be pageContext.forward("/resource.jsp");



Is there any difference in what i specified and what you suggested ??



And i am using this inside the servlet , and not in jsp



Difference is highlighted in bold.

And the other difference is mentioned by Balu above.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Mohammed and Balu .



API of the PageContext class .
 
Are you okay? You look a little big. Maybe this tiny ad will help:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic