Search code examples
jspurlstruts2struts-tags

<s:url> namespace attribute in Struts2


My Code is:

<s:url action="work-items_input" includeParams="get" var="wiLink"  namespace="">
    <s:param name="workItemVO.workItemId" value="'5'"></s:param>
</s:url>    
<s:a action="%{wiLink}" namespace="/myaccount"><s:property value="subject"/></s:a>

In my application's ContextRoot is "pmp". Here above is generating link as

/pmp//pmp/myaccount/work-items_input.action?ajaxRequest=true&workItemVO.workItemId=5

above we can see context path is coming twice. /pmp//pmp... this is wrong. How to remove one extra context path?


Solution

  • Remove the action and namespace attributes from the <s:a> tag, and use instead the <s:url>'s one with the href attribute:

    <s:url action="work-items_input" includeParams="get" var="wiLink"  namespace="/myaccount">
        <s:param name="workItemVO.workItemId" value="'5'"></s:param>
    </s:url>    
    <s:a href="%{wiLink}"><s:property value="subject"/></s:a>
    

    That should be enough.