-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Donald,

On 8/24/2011 2:23 PM, Donald Jolley wrote:
>> how can RequestDispatcher perform the forward
> 
> I'm not sure.  My objective is to institute a way of conditionally
> jumping from a servlet to a specified page.

This does work. You have to do something like the following:

public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
  throws IOException, ServletException
{
  // ... do something interesting

  if(/* whatever decision you have to make */)
  {
    request.getRequestDispatcher("/target/url")
           .forward(request, response);

    return;
  }

  // do whatever the default operation of this servlet is
}

That last "return" may or may not be required, but if you expected
that the forwarded request would produce a complete response, then
it's the proper thing to do.

Note that the forward() call is synchronous and /actually invokes the
other servlet/ and /then returns to your code/. This isn't like
telling the container that, after your method ends, you want the other
servlet to take over. Your servlet is calling the other one,
indirectly through the RequestDispatcher.

This surprises some people sometimes :)

If your servlet won't compile, then you need to figure that out. Look
at the entire example -- it should probably include some "import"
statements at the top of the file. There's no requirement that the
method arguments be named "request" and "response" though they often
are, by convention (I've also seen "req/rsp", "rq/rp",
"hsrRequest/hsrResponse" and some others, but most people just stick
with "request/response").

If things aren't actually working once you get your code compiled and
running, let us know and maybe we can help.

But the request dispatcher definitely works.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk5VSJsACgkQ9CaO5/Lv0PAPDACfbsLy6wgXO5AuCwroa+srG3cp
1u4AoLx+9kPekqFBQRfSLdPIF6Bivj7m
=yQLH
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to