Search code examples
javahtmljspstruts2struts

How to configure s:url to return the absolute path, so that it doesn't get affected by html base?


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


Solution

  • 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.