URL does not change even after changing actionThis is likely a forward vs. redirect 
issue...

Forward: happens on the server, one action forwards the current request to another. 
The browser never knows about it, so the URL in the address bar does not change. If 
the original request was for action1 and then it forwards to acion2, the URL in the 
browser will still be for action1.

Redirect: server sends a response to the original request that tells the browser to 
request something else. The browser then makes another request for the other action, 
and the browser's address bar reflects this. If the original request is for action1, 
the server can respond by teling the browser to request action2. The browser makes the 
request for action2, and the URL for action2 will be in the address bar at that point.

In Struts, you setup Struts "forwards" for both forwards and redirects. To get a 
redirect for a Struts forward element, you just add an attribute to the forward 
element, e.g.: <forward name="success" path="/action2" redirect="true"/>

Which one of these to use depends on the circumstances. I typically like to respond to 
requests that change something in the database [typically a POST with parameters for 
changing a row (or rows) in the database] with a redirect. Otherwise, forwards are 
usually more appropriate (e.g. action forwarding to JSP to render the view).

One issue to consider is that a redirect will mean that a new request is used for 
action2, so anything that action1 puts into the request scope will not be available in 
action2. If you need to pass some info from action1 to action2, you'll need to do it 
via a query string on the URL you are redirecting to. You don't usually want to put 
these query string parameters in the <forward/> element's path since their values will 
likely need to be dynamic. In that case, you'll need to grab the ActionForward and 
clone it and then add on or adjust the query string as needed for the context of the 
current request. There might be better ways to do that now, but that is what we did 
with Struts 1.02. Note that redirects are always GET requests -- you can redirect to a 
POST, so the query string is the only way to pass info. You could stick it in the 
session, too, but that is generally a sloppy practice and should only be a last resort 
made with your eyes open to the potential consequences (several browser windows with 
the same session stepping on each other, junk accumulating in the session, old values 
hanging around in the session messing up future requests from the same browser window, 
etc.).

-Max
  ----- Original Message ----- 
  From: Namasivayam, Sudhakar (Cognizant) 
  To: Struts Users Mailing List 
  Sent: Sunday, February 08, 2004 10:49 AM
  Subject: URL does not change even after changing action 


  hi, 

     Even after i call another action from the current action the url still remains 
the previous action .. So if i refresh the current page the previous action is called 
not the current one.. how do i solve this ???




  Thanks & regards, 
  Sudhakar 






------------------------------------------------------------------------------


  ---------------------------------------------------------------------
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to