I'm using Struts 2. I have this line in my execute method ...
return new ActionForward(redirect);
Where redirect is a URL to a site potentially different than that of my server. Is it possible to detect a timeout from that site and if so, redirect the user to a page of my choosing? If it is possible, how can I set the timeout wait period?
ActionForwards are from Struts 1. That code won't have meaning.
Forwards and redirects are very different things: forwards include the content of another webapp resource in the current response; AFAIK they have to be local to the webapp. Redirects instruct the browser to request another resource, which may be local or remote.
If you're actually talking about redirects, then timeouts are detected by the *client*, not the server. In order for the *server* to detect a timeout it would have to create its own request (through, for example, an HttpClient). If you're actually talking about a forward, then I'm not sure if it's possible; I've never tried to forward to a non-local resource.
But the bottom line is that at some point you have to decide if you're using Struts 1 or Struts 2.
Joined: Jul 02, 2008
If the code I included will not work in Struts 2, what is the proper way to do a forward? - Dave
Struts or no, it sounds like you want to do a redirect. At least if you're sending the request off to another URL which isn't in your application, you're going to have to do a redirect. And as David Newton, said, what happens when you do that is that you reply to the browser with a code which says "Go to this other URL instead". Once you reply, that's it. Your code is finished. The browser may or may not be able to connect to that other URL, but there's nothing your code could do about it. Doesn't matter what version of Struts you're using or even if you're not using Struts at all.
The correct way to do a "forward" is to define a "dispatcher" result type in your action's configuration (XML- or annotation-based). You can include parameters in your result configuration, see here for general result configuration, and here for more information on parameter usage.
Again, I do not believe this will work with non-webapp resources, but maybe it will.
Do you have a working S2 application using ActionForwards?!