4

I have an application that needs to redirect to several internationalized urls, ie

  • www.mydomain.com/us/myapp/xxx.action
  • www.mydomain.com/fi/myapp/xxx.action
  • dwww.mydomain.com/de/myapp/xxx.action

We have a proxy server where the url is mapped to myapp/xxx.action?country=us and redirected to the application server. The problem is how to redirect to the next action with the format above?

Now the url for the next action is generated by using country from url and adding context path and action name and opened by javascript in jsp.

Example:

<body onload="javascript:top.location='${generatedPath}';return true;"></body>

Example form submit:

<s:form id="form" action="%{generatedPath}" theme="simple" method="post" includeContext="false">

Would like to do this in a less hackish way, and have tested a bit with struts.xml and type redirectAction, but cannot seem to be able to generate the url above, with the country before context path. I have not found any struts2 documentation describing this, but are unsure if im looking at the right place as well? Should this be handled elsewhere?

user976308
  • 61
  • 1
  • 2

1 Answers1

0

I think the following discussion can help you:

How to do dynamic URL redirects in Struts 2?

Here, your result will look like:

<result name="redirect" type="redirect">${url}</result>

And, the action would be:

private String url;
private String country;

public void setCountry(String country) {
   this.country = country;
}

public String getUrl()
{
 return url;
}

public String execute()
{
 url = "www.mydomain.com/" + country + "/myapp/xxx.action";
 return "redirect";
}
Community
  • 1
  • 1
James Jithin
  • 10,183
  • 5
  • 36
  • 51
  • Thanks for your reply. I have looked at that discussion and ended up implementing in a similar way, using `code` false ${generatedPath} `code`. This works fine and is a lot better than what we had previously, but am still wondering if there is a standard way of dealing with locale in url like this.. – user976308 Oct 04 '11 at 08:02
  • Sorry, struggled a bit with the code mark up.. ` false ${generatedPath} ` – user976308 Oct 04 '11 at 08:09