I check if the current URL ends with '/' then the variable slash
is empty. Else the slash
is '/'.
<c:set var="slash" value="/"/>
<c:set var="uri" value="${requestScope['javax.servlet.forward.request_uri']}"/>
<c:if test="${fn:substring(uri, fn:length(uri)-1, fn:length(uri)) == '/'}">
<c:set var="slash" value=""/>
</c:if>
Next, basing on the variables slash
and uri
, some text is appended to the current URL and the new link is build.
<a href="${uri}${slash}${cd.toString()}/">${cd.toString()}</a>
It was working when the code was on the same page where the new URL is build. When I applied Apache Tiles, the first code is put into main.jsp:
<body>
<c:set var="slash" value="/"/>
<c:set var="uri" value="${requestScope['javax.servlet.forward.request_uri']}"/>
<c:if test="${fn:substring(uri, fn:length(uri)-1, fn:length(uri)) == '/'}">
<c:set var="slash" value=""/>
</c:if>
<div id="headerId">
<tiles:insertAttribute name="header" />
</div>
<div id="bodyId">
<tiles:insertAttribute name="content" />
</div>
</body>
and the link are build in content.jsp:
<a href="${uri}${slash}${cd.toString()}/">${cd.toString()}</a>
But in content.jsp the variables uri
and slash
are empty.