There are legitimate uses for both forwards and redirects. forward() works best when one component must perform business logic and share the results with another component; sendRedirect() works best when the client should be redirected from one page to another. It's tempting to use forward() instead of sendRedirect() for simple redirect duties, because a forward() operates within the server and executes faster than a sendRedirect(), which requires round-trip communication with the client. But this causes problems with relative URL handling because sendRedirect() gives the client notice that a file was served from the document root, whereas forward() gives no such notice and relative URLs end up broken. sendRedirect() also makes it easier to dispatch to resources within other contexts because no getContext() lookup is required.
As Jason Hunter recommends: "...use sendRedirect() whenever possible and ... use forward() only when required." ("Java Servlet Programming, 2d Ed.," O'Reilly 2001: 374-375). Mark -----Original Message----- From: Chris Wall [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 20, 2002 7:21 PM This is a greater issue then not. Servlet to servlet forwards are not recognized in the browser's address indicator. Not only is it confusing to the user, but a nightmare to program for. Most notable pain is that if the browser is refeshed/reloaded, the reload is not of the current view but of the previous servlet. For example, if Servlet A forwards to Servlet B, Servlet B does its stuff and renders it's own view. The browsers address still reads Servlet A including any query string params. If the user then refreshes the view, the browser sends Servlet A, and its query string, to the server for rework. This is not desired, because it is Servlet B that needs to be refreshed. ----- Original Message ----- From: "Craig R. McClanahan" <[EMAIL PROTECTED]> Sent: Monday, June 24, 2002 12:11 PM > > On Mon, 24 Jun 2002, Chris Wall wrote: > > > Date: Mon, 24 Jun 2002 09:22:17 -0700 > > From: Chris Wall <[EMAIL PROTECTED]> > > Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]> > > To: Struts Users Mailing List <[EMAIL PROTECTED]> > > Subject: Servlet RequestDispatcher and browser URL refresh > > > > Has anyone found a way to refresh the browser's address indicator after a > > servlet to servlet dispatch? Another words, when a > > RequestDispatcher.forward is execute from servlet A, flow within the browser > > shifts to the output of servlet B. But, the browser's URL address bar still > > indicates the previously executed servlet, servlet A. Is there a way to > > notify the browser of a URL change so that the address bar accurately > > displays the current servlet, servlet B? > > > > Since the browser has no clue that the request was forwarded, this cannot > be done without using a redirect instead of a forward. This costs you so > much (performance loss, inability to use request attributes) that it's not > worth it. > > You're much better off training your users that the location bar is > totally irrelevant in webapps. For stubborn people who don't get the > message, you can play nasty games like use a single-frame frameset (so > that the location bar never changes), or open a window with no location > bar -- but web apps are not the same thing as web sites. > > > Thank you. > > > > Craig -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>