Rupesh Choubey wrote:

>
>
> Could anyone help with the following issues:
>
> ** How do I call a servlet FROM a JSP? something like <!
> RequestDispatcher.forward ??????????
>
> ** How do I call a servlet FROM another servlet? (i know its got to do
> with the RequestDispatcher...but i couldnt make it work....could
> someone send me code snippets)
>
> thanks in advance,
> rupesh.

Assume you have two servlets, mapped to "/servletA" and "/servletB".

In a JSP page, you can include the output from a servlet like this:

    <jsp:include page="/servletA" />

or forward to that servlet (thus ignoring the page you are going from)
like this:

    <jsp:forward page="/servletA" />

If you are in servlet A and you want to call servlet B, you'd do one of
the following (depending on whether you wanted to include or forward):

    RequestDispatcher rd =
        getServletContext.getRequestDispatcher("/servletB");
    rd.include(request, response);

    RequestDispatcher rd =
        getServletContext.getRequestDispatcher("/servletB");
    rd.forward(request, response);
    return;

The most important thing to get right is the path -- it needs to start
with a slash, and is interpreted as relative to the root of the web
application you are currently running in.

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to