In this section, you will learn about dispatch method of AsyncContext Interface.
The AsyncContext Interface dispatch() method is of two
The dispatch method takes no argument.
It uses the original URI as the path. If the AsyncContext was initialized
via the startAsync(ServletRequest,ServletResponse) and the request passed is
an instance of HttpServletRequest, then the dispatch is to the URI returned
by HttpServletRequest.getRequestURI(). Otherwise the dispatch is to the URI of
the request when it was last dispatched by the container.
void dispatch(java.lang.String path)
The dispatch method takes a
String argument as path which must be inside the scope of the ServletContext. This path must be relative to the root of the
and begin with a ?/?.
The dispatch method accepts a String argument describing a path
within the scope of the ServletContext specified. This path must be
relative to the root of the ServletContext specified and should
starts with a ?/?.
Given below a sample snippet using dispatch() method :
Consider a scenario where we have three Servlets - X , Y and Z which have
URLs : /x , /y & /z :