struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Law <>
Subject Is this expected behaviour for <s:url> tag?
Date Thu, 06 Aug 2009 16:51:19 GMT

I have actions that sit underneath a set of namespaces. The namespace conveys
a piece of information to the action like a poor-man's REST.


I need to construct some links from within the JSP that is hit by the
individual actions and have them point at a different action within the same

e.g. links generated in the page when accessed via /Cow/ should point to
<context>/Cow/Action2.action and links generated in the page when accessed
via /Pig/ should point to <context>/Pig/Action2.action

If I construct my links to contain href urls derived from <s:url> tags that
look like <s:url action="Action2"> then I get a URL that looks like
<context>/Action2.action. This is no good.

So I figured that I had to set the namespace, which was a pain but I could
always rework the code so that the action knows what namespace it is working
in. I did that, and I set my tag to look like this <s:url action="Action2"
namespace="putItHere"> just to prove that it would work and I ran the

To my surprise, I got a URL that looked like
<context>/Pig/putItHere/Action2.action when I ran through the Pig namespace
and <context>/Cow/putItHere/Action2.action when I ran through the Cow

If I rework the namespace to include a leading slash (which was what I
intended to do the first time, but I mistyped it) then my tag looks like
<s:url action="Action2" namespace="/putItHere"> and my URL looks like
<context>/putItHere/Action2.action regardless of which namespace the code is
run through.

So I thought that I would try the obvious thing next and coded my tag to say
<s:url action="Action2" namespace=""> and I got the same outcome as if I had
specified <s:url action="Action2"> i.e. no namespace inserted.

There is NO way that I have found to do what I want to do which is have the
current namespace inserted into the generated URL without anything extra

Have I missed something? (obvious or not so obvious)?

Thanks in advance for anything anyone can suggest.


View this message in context:
Sent from the Struts - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message