'struts2 action redirect to "outside" url
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
Solution 1:[1]
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;
}
}
Solution 2:[2]
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.
Solution 3:[3]
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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | zb226 |
| Solution 2 | zb226 |
| Solution 3 | BartjeV |
