1

Does RequestDispatcher object exits as it is an interface and as for i know we cant create an object to interface. So what is happening in following code

RequestDispatcher requestDispatcher = request.getRequestDispatcher('somePage');  

Are we creating object to RequestDispatcher or to subclass that implements RequestDispatcher.

Thanks in advance.

Ravi Godara
  • 497
  • 6
  • 20
  • 3
    To answer question from title: it most probably depends on Container. On Glassfish 4.0 if you print result of `request.getRequestDispatcher("someResource").getClass()` you will see `org.apache.catalina.core.ApplicationDispatcher`. – Pshemo Feb 26 '14 at 11:09

2 Answers2

0

RequestDispatcher is an interface and we can't create an object obviously with that. So, it is an object of the class that implements RequestDispatcher that you get when the calling getRequestDispatcher().

You need to have the source code of the Servlet implementation(this depends on the container that you are using) to see the class that is providing the implementation.

Varun
  • 1,014
  • 8
  • 23
0

You are right, RequestDispatcher is an interface you we can not create an object of this.

Now see:

request.getRequestDispatcher('somePage'); This method returns a class which implements RequestDispatcher and that class is totally depends upon the server which you are using. For Ex. In case of Glass Fish server, it returns org.apache.catalina.core.ApplicationDispatcher object and it has already told by @Pshemo.

user207421
  • 305,947
  • 44
  • 307
  • 483
Suneet Bansal
  • 2,664
  • 1
  • 14
  • 18