Reputation: 1231
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.
Upvotes: 1
Views: 849
Reputation: 1150
This is not to do with Tiles. You'd hit the same problem even using <jsp:include …/>
<c:set …/> by default puts variables into page scope. You'll need to do the following to have those variables available in the next page as well
<c:set var="slash" value="/" scope="request"/>
Upvotes: 2