Redirecting directly from action definition

In my struts config file, I have an action def like this

<action path=“/somepage” forward=“.abc.xyz.somepage”>
<set-property property=“secure” value=“false”/>
</action>

Instead of abc.xyz.somepage, I want to redirect this link to a totally different domain, say, http://www.example.com. If it had a forward def, I can put the redirect in it. How do I do it directly, in this case?

Frankly, no clue. But, I’m sure you already know several work around in this.

  1. response.redirect in jsp or action class
  2. javascript

or even fancier solution would be playing w/ servlet. Example, if you have the url

http://yoursite.com/redirectURL?site=blahblah

intercept the url and redirect… yeah it’s very manual. Anyways, good luck.

I did try response.redirect, for some reason it isn’t working. I read somewhere that I need to use return; after response.redirect, tried that too, no luck.

Javascript - nope, not a good solution. Plus it’ll be a pain, if I have to pass some other parameters along with the URL string.

If this doesn’t work, I think you should send an e-mail to Sun “You Suck!!!”

response.sendRedirect(“http://www.microsoft.com”);

So what are you trying to do with the redirect? My guess is you’re trying to record that you are redirecting someone to another site. Is this close?

If you’re doing that you could try to do the following:

Create a very basic Action that all it does is redirect a request to a url that is passed in as a parameter.


public class RedirectAction extends Action
{
    public ActionForward execute(ActionMapping mapping, ActionForm form, ServletRequest request, ServletResponse response) 
    {
        String url = request.getParameter("url");
        
        // Log the redirect here...

        ActionForward actionForward = new ActionForward();
        setPath(url);
        setRedirect(true);

        return actionForward;
    }
}

Then just call the above action when you want to record a external redirect.


<a href="../actions/redirect.do?url=http://abc.external.outside.com/website">Outsite Website</a>

Also, it seems as if you’re using your forwards incorrectly (at least for Struts 1). I don’t think forward is an attribute of action. I thought it was its own separate tag. Here is an example:


<action path="/[I]somepage[/I]" 
        type="[I]the full classpath and name of your class[/I]" >
    <forward name="success" path="http://abc.external.outside.com/website" redirect="true" />
</action>

I think that should work too.

Best of Luck.