문제

I have a menu that's common to most of my site. If I'm on Page 1, for example, I want the "Page 1" link in the menu to be highlighted so I can compare the current action to "page1.action" and dynamically add the appropriate CSS class based on the comparison.

I've tried the following from various other Stack Overflow answers but none of them are giving me what I want:

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/>

Here's the output:

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: 

I basically want something where I can do this:

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

For what it's worth, we're using Struts 2.3.8.

도움이 되었습니까?

해결책

Try with this code

<c:set var="actionName">
    <s:property value="%{#context['struts.actionMapping'].name}"/>
</c:set>
action name: ${actionName}<br/>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top