2

Using <base href="<s:url value="/"/>" target="_blank"> resolves all images & stylesheets properly, when there are many namespaces like /, /admin etc.

But the action urls also get interrupted by base tag.

Suppose the current browser url is http://context/admin/dashboard

<s:url value="clients" namespace="admin"/> returns clients which in the browser gets resolved to http://context/clients instead of http://context/admin/clients

Is there a way to tell s:url to render absolute URLs instead of relative ?

http://struts.apache.org/development/2.x/docs/url.html

Roman C
  • 49,761
  • 33
  • 66
  • 176
coding_idiot
  • 13,526
  • 10
  • 65
  • 116
  • http://stackoverflow.com/a/1889898/1654265 and http://stackoverflow.com/a/1889957/1654265 – Andrea Ligios Mar 11 '14 at 09:37
  • @AndreaLigios thanks for the above links. Is there any way by which `s:url` tag can render/return an absolute url ? – coding_idiot Mar 11 '14 at 11:40
  • I don't know, but it's strange behaviour to ignore the namespace... can you post the generated html by an s:property of the s:url tag ? To be sure it is not s:a fault – Andrea Ligios Mar 11 '14 at 13:21

1 Answers1

1

You have wrong value to the tag attribute namespace. The namespace value should correspond to the package attribute and use the path value calculated from the web content root. So, if you have declared the namespace="/admin" this value should be used to the corresponding url tag attribute.

<s:url action="clients" namespace="/admin"/> 

The result outputs to HTML, and you could see what value is rendered.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • actually, using just `admin` (without slash) works. Although I should be using `action` attribute, not the value attribute. After using `action` instead of `value` it rendered relatively good path which didn't got affected by `html base` tag. – coding_idiot Mar 11 '14 at 22:47
  • yes, it works because the `url` tag build the URL which is mapped to the action in the namespace specified and if it fails to build the current action URL is used which is relative. – Roman C Mar 12 '14 at 09:04