How does getRequestDispatcher("xxx")
get called from getServletContext()
in the example below? How does calling procedures like this work in general? Please give me a clear picture about this context.
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp");
dispatcher.include(request, response);
in general, method chaining is a good practice achieving fluent and flexible interfaces. Generally... to achieve it, you just do your code and return the current object. For example, in Java:
Returning the current object provides the same API over and over... but, by each iteration the object gets changed, step by step, orderly.
getServletContext()
returns aServletContext
object, which has a method calledgetRequestDispatcher()
. Your line of code is just shorthand for two method calls, and is equivalent to this code: