• Post Reply Bookmark Topic Watch Topic
  • New Topic

difference in forwarding using PageContext.forward and RequestDispatcher.forward

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • 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?

 
Shailesh Narkhede
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Mohamed Inayath
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Thank you Mohammed and Balu .



API of the PageContext class .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!