Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Servlets Servlet3 AsyncContext Interface dispatch method

Related Tutorials


 
 

Share on Google+Share on Google+

AsyncContext Interface dispatch method

Advertisement
In this section, you will learn about dispatch method of AsyncContext Interface.

AsyncContext Interface dispatch method

In this section, you will learn about dispatch method of AsyncContext Interface.

The AsyncContext Interface dispatch() method is of two types :

  • void dispatch()

    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 ServletContext and begin with a ?/?.

  • void dispatch(ServletContext context, java.lang.String path)

    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 ?/?.

EXAMPLE

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 :

Within Servlet X, we have :

request.getRequestDispatcher("/x").forward(request, response);

Within Servlet Y, we have :

request.getRequestDispatcher("/y").forward(request, response)

Within Servlet Z, we have following two statements :

  • request.startAsync().dispatch(); // to /y
    It will dispatch to the last dispatched URI, which relates to /y.

  • request.startAsync(request, response).dispatch(); // to /z
    It will dispatch to request.getRequestURI(), which corresponds to /z.

 

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 15, 2012

Related Tutorials

Discuss: AsyncContext Interface dispatch method  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com