0

There are different ways of creating a RequestDispatcher Object:

Method 1: Using HttpRequest Object

RequestDispatcher rd=request.getRequestDispatcher();

Method 2: Using ServletContext Object

RequestDispatcher rd=getServletContext().getRequestDispatcher();

Method 3: Using ServletContext & ServletConfig Object

RequestDispatcher rd =getServletConfig().getServletContext().getRequestDispatcher();

What are the differences between these 3 methods and which one should i prefer to call a JSP page from a servlet/JSP in a dynamic web-app?

  • Possible duplicate of [ServletContext.getRequestDispatcher() vs ServletRequest.getRequestDispatcher()](https://stackoverflow.com/questions/1411114/servletcontext-getrequestdispatcher-vs-servletrequest-getrequestdispatcher) – ST. Kee Jul 06 '18 at 01:45
  • There's only 2 method, `getServletConfig().getServletContext()` is just same as `getServletContext()`. Please see this [answer](https://stackoverflow.com/questions/1411114/servletcontext-getrequestdispatcher-vs-servletrequest-getrequestdispatcher) – ST. Kee Jul 06 '18 at 01:46

0 Answers0