Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which class provides the implementation for getRequestDispatcher() method

Tags:

java

servlets

The getRequestDispatcher() method of ServletRequest interface returns the object of RequestDispatcher.

I know that getRequestDispatcher() method is in the Interface ServletRequest. As it is an interface, it won't define the method.

Furthermore, this interface is again inherited in another interface HttpServletRequest. But being an interface, it won't define its methods.

Now, after carefully checking the JavaDocs, I could not find any class that implemented either of these two interfaces, and defined the getRequestDispatcher() method.

So I was wondering where did they define this method

Thanks in advance.

like image 217
probuddha singha Avatar asked Oct 30 '25 10:10

probuddha singha


1 Answers

The class which implements is org.apache.catalina.connector.RequestFacade , in case of TOMCAT container. The implementation is basically dependent on containers & every container has its own implementation adhering to the J2EE Specs.

Use the below code to check the implementation class :-

public class TestServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
            throws ServletException, IOException {
        System.out.println(httpServletRequest.getClass());
    }
}

Output :- org.apache.catalina.connector.RequestFacade

You can see this class Offical Doc here, and can check that it has implemented the interface javax.servlet.ServletRequest and its methods like getRequestDispatcher() etc.

like image 52
AnkeyNigam Avatar answered Nov 01 '25 23:11

AnkeyNigam