Carles Pi-Sunyer wrote:

> I'm trying to capture the name of the page that forwards to a new page.
>
> My specific situation is that I have three pages: A, B, C. Normally A
> has a link to C:
>
> A -> C
>
> Sometimes if a condition is not met (insufficient user information), C
> forwards to B:
>
> A -> C -forward-> B.
>
> What I would like to do is let B know the name of C, so that after the
> user information is gathered, B can send the user back to C.
>

If you mean <jsp:forward> when you say "forward", one way to do this would be to
add an object to the request attributes.  For example, you could do something like
this:

    <% request.setAttribute("cameFrom", "C"); %>
    <jsp:forward page="B" />

and, in page B, something like this:

    <%
        String cameFromPage = request.getAttribute("cameFrom");
        if (cameFromPage == null) {
            ... came from someplace else ...
        } else if (cameFromPage.equals("C")) {
            ... came from page C ...
        } ... and so on ...
    %>

If any of A, B, and C were servlets instead of JSP pages,
RequestDispatcher.forward() can be used for exactly the same sort of thing.  I use
this technique a lot because I have my input forms submit themselves to a servlet,
which performs the requested action, stores beans in either request or session
scope (depending on how long I want to keep them), and forwards to the appropriate
JSP page for displaying the results.

If you are using sendRedirect() for forwarding, the other suggestions to pass a
parameter in the URL will work; but you will find that <jsp:forward> is faster
because you're skipping the extra trip back t the client.


> Thank You,
> Carles
>

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