- Posted by: Oon Kean Lin
- Posted on: July 15 2002 02:40 EDT
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 http://developer.bluestone.com/Scripts/SaIsapi.dll/StrutsTrailMap.class/struts-trailmap/Trail6.htm , you can see the below mapping :
<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 http://developer.bluestone.com/Scripts/SaIsapi.dll/StrutsTrailMap.class/struts-logon/success.jsp
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>
- Struts does not return the proper URL to the Web Browser ? by Klaas van der Ploeg on July 15 2002 04:15 EDT
- Struts does not return the proper URL to the Web Browser ? by Chuck Cavaness on July 15 2002 07:19 EDT
- Struts does not return the proper URL to the Web Browser ? by Oon Kean Lin on July 15 2002 21:35 EDT
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.
In the forward element for the action, you can set the redirect attribute to equal 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.
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.