You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Craig R. McClanahan" <Cr...@eng.sun.com> on 2000/09/21 23:24:24 UTC

Re: login.do instead of login.jsp

Naveed Khan wrote:

> Folks:
>
> I have a question related to the struts-example webapp. On login.jsp page
> when user enters incorrect user id and/or password the url page loaded in
> the browser is shown is localhost/logon.do instead of localhost/logon.jsp.
> Why is it so ?? Althought in the action.xml the path attribute for forward
> element is "/logon.jsp". Since it is logon.do, when user press refresh
> button of browser he/she may resubmit the form again ..
>
> I would appreciate if anyboday can throw light on it ..
>

Welcome to the wonderful world of the RequestDispatcher :-).

The Struts controller servlet uses a feature of the servlet specification, the
RequestDispatcher, to forward control from the action procedure that is
invoked (the one identified by "/logon.do") to whichever JSP page should
display the response.  This all happens on the server side, so the client
browser has no idea what happened.  In fact, the logon forwards to two
different places (back to the logon form or forward to the menu) depending on
whether the logon is successful or not, and the browser's location bar is the
same in either case.

The only way to change what the location bar shows would be to use a
HttpServletResponse.sendRedirect() instead.  However, this has two negative
consequences:

* It takes longer (sometimes a lot longer) because there is an extra
  round trip conversation with the user's browser.

* You lose the ability to pass beans in request scope from the
  action class to the JSP page, because the redirected request
  comes in separately.

Basically, the URL shown in the location bar of a web app using this technique
has very little to do with what is actually displayed.  It only shows the
address that the user submitted the form to.

One of the consequences of this is that you should design your user interface
to include all the appropriate navigation controls (essentially the same
design principle used for GUI programs) so that the user is not tempted to
bookmark things in the middle, or use the "Back" and "Forward" buttons to move
around.

>
> thanks ..
>
> naveed
>

Craig McClanahan

PS:  You can forward directly from a JSP page as well, using <jsp:forward>,
but this is generally not required in a Struts based application where all
interactions with the user are submitted to the (single) controller servlet.

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat