I have a menu common to most of my sites. For example, if I am on page 1, I want to highlight the “Page 1” link in the menu to compare the current action with “page1.action” and dynamically add the corresponding CSS class based on the comparison.
I tried the following of the other stack overflow answers, but none of them give 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: ${
Here's the conclusion:
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:
Basically I 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 use Struts 2.3.8.
source
share