java – 如何确定我在JSP中呈现的Struts操作?

我有一个菜单,这是我网站的大部分内容.例如,如果我在第1页上,我希望突出显示菜单中的“Page 1”链接,以便将当前操作与“page1.action”进行比较,并根据比较动态添加相应的CSS类.

我尝试了以下各种其他Stack Overflow答案,但没有一个能给我我想要的东西:

req.contextPath: ${req.contextPath }<br/>
req.requestURL: ${req.requestURL }<br/>
pageContext.request.requestURL: ${pageContext.request.requestURL }<br/>
pageContext.request.requestURI: ${pageContext.request.requestURI }<br/>
pageContext.request.servletPath: ${pageContext.request.servletPath }<br/>
action name: ${com.opensymphony.xwork2.ActionContext.name }<br/>
action name 2: ${#context['struts.actionMapping'].name}<br/>

这是输出:

req.contextPath: /myContextRoot
req.requestURL: http://localhost:9080/myContextRoot/WEB-INF/app/layout/simpleLayout.jsp
pageContext.request.requestURL: http://localhost:9080/myContextRoot/WEB-INF/app/layout/simpleLayout.jsp
pageContext.request.requestURI: /myContextRoot/WEB-INF/app/layout/simpleLayout.jsp
pageContext.request.servletPath: /WEB-INF/app/layout/simpleLayout.jsp
action name:
action name 2: 

我基本上想要一些我能做到的事情:

<c:choose>
    <c:when test="${pageContext.request.requestURI == 'page1.action')}">
        <c:set var="page1ButtonClass" value="class=\"active\""/>
    </c:when>
</c:choose>

对于它的价值,我们使用的是Struts 2.3.8.

最佳答案 尝试使用此代码

<c:set var="actionName">
    <s:property value="%{#context['struts.actionMapping'].name}"/>
</c:set>
action name: ${actionName}<br/>
点赞