Invoke a servlet from a servlet

There are couple of ways to do so:

  1. Send a HTTP request
    To invoke a servlet that requires authentication, in addition to creating the URL object, you need to pass authentication cookies too.

    URL url = new URL("http://blah");
    URLConnection con = url.openConnection();
    con.setRequestProperty("Cookie", request.getHeader("Cookie"));
    con.connect();
  2. RequestDispatcher
  3. Send a redirect

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.