Struts does not return the proper URL to the Web Browser ?


Web tier: servlets, JSP, Web frameworks: Struts does not return the proper URL to the Web Browser ?

  1. Hi ,
    I have a scenario in using Struts that while a form request is submitted to an Action , the action will use ActionMapping.findForward() to forward the request to another Action , and finally to a JSP page. However , after the JSP page is returned to the browser , the browser's address bar does not show the actual JSP page location. Instead it still shows the URL that is mapped to the first Action.
    For example (this sequence of the example is a bit different from my scenario , but the result is similiar) , examine Bluestone's Struts example at :
    Looking at the struts-config.xml which is mentioned at , you can see the below mapping :
    <action path="/logon"
        <forward name="success" path="/success.jsp" />
        <forward name="failure" path="/failure.jsp" />

    After successful login , I would expect the URL shown on the Web Browser's address bar to be something like
    Instead I got this : <br>

    Is this intentionally done by Struts ? What is the reason behind this ? Is there a way to change it so that it displays the actual URL ?

    <br>Thanks for reading this.<br>
  2. When forwarding a request using the RequestDispatcher, it is not using the Location HTTP-header for forwarding the request, but it is using servlet-chaining to forward the request. So, the client doesn't really know about your http-request being forwarded to another servlet/jsp.

  3. In the forward element for the action, you can set the redirect attribute to equal true:

      redirect="true" />

    This will cause a redirect to occur, instead of a forward and the client browser will change to the proper URL.

    The problem with this approach is that any data that is stored in the request will disappear because a new request is issued for the redirect. It will fix your original problem, but it causes much, much worse.

    The truth is that you have to train the users just to ignore the browser URL. In general, they should never mess with or worry about the URL. I've seen some apps actually hide the URL field.

  4. Thanks for the useful explanation and tips. It's very much appreciated. It sure helped me save countless hours of trying to debug something that is intentional.