0

i need my action to be able to redirect to outside url address, lets say for exemple http://google.com

Right now i have:

<default-action-ref name="home" />
<global-results>
  <result name="redirect" type="redirect">${targetUrl}</result>
</global-results>

if in targetUrl i have http://google.com my action will call home page and it iwll not redirect to google.

I saw the similar question here How to do dynamic URL redirects in Struts 2? but I can see that only the last part of url is being used as a destination for the redirection.

can you please help me?

thanks

Community
  • 1
  • 1
gospodin
  • 1,133
  • 4
  • 22
  • 42

3 Answers3

0

To redirect to a specific action from an interceptor I did the following:

response.sendRedirect("specificAction.action");
return null;

No need for global results in this case.

zb226
  • 9,586
  • 6
  • 49
  • 79
gospodin
  • 1,133
  • 4
  • 22
  • 42
0

This will solve your question. From the Action class from you returning the redirect the targetUrl should be member variable for the class and should have public getter and setter.

public class YourAction extends ActionSupport {
    private String targetUrl;

    public String execute() {
         return "redirect";
    }

    public String getTargetUrl() {
        return targetUrl;
    }

    public void setTargetUrl(String targetUrl) {
        this.targetUrl = targetUrl;
    }

}
zb226
  • 9,586
  • 6
  • 49
  • 79
0

You can do this by using the Http Header result type. That will work because a redirect instruction to the browser is simply a status code plus 'Location' header.

<result name="startCheckout" type="httpheader">
    <param name="status">303</param>
    <param name="headers.location">${externalUrl}</param>
</result>
BartjeV
  • 63
  • 1
  • 4