简体   繁体   中英

Need to get action url by action name in struts2

I am new to Struts2. I have to create breadcrumbs in an application so what I want to do is to set a Map with all label/url of all links in breadcrumbs. My problem is that I don't know how to get the URL of an action inside the action class.

eg.

private Map<String, String> breadcrumbs;

public String MyAction() throws Exception {

    breadcrumbs.put("List", SomeClass.getUrl("listAction"));
    breadcrumbs.put("Project", SomeClass.getUrl("projectAction"));
    breadcrumbs.put("Chart", SomeClass.getUrl("chartProjectAction"));

    return Action.SUCCESS;
}

So, what should I use instead of that SomeClass to get the Url of an action?

Thanks in advance, Ciprian

Eventually, as Aleksandr M suggests, I've send from the Action the action names and compile the URL directly from the .jsp file using s:url tag

<s:iterator value="breadcrumbs" status="st">
    <s:if test="#st.last == true">
        <li class="active"><s:property value="key" /></li>
    </s:if>
    <s:else>
        <li><a href="<s:url action="%{value}" />"><s:property value="key" /></a></li>
    </s:else>
</s:iterator>

Hope this will help someone!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM