开发者

Trying to do an OR test with JSTL inside my jsp template

i have the following code from my JSP which doesn't quite work:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<c:set var="contextPath" value="${pageContext.request.contextPath}" />
<c:set var="requestURI" value="${pageContext.request.requestURI}" />
<c:set var="isPeople" value="${fn:contains(requestURI, '/People/')}" />
<c:set var="isJobs"   value="${fn:contains(requestURI, '/Jobs/') || fn:endsWith(requestURI,contextPath+'/')}" />

Basically, isPeople is working fine - it开发者_StackOverflow中文版 checks to see if the user is on any of my pages that have '/People/' in the url, and uses that later on down to show the appropriate submenu.

Now i wand the isJobs to be true if they are at either '/Jobs/*' or the application root, but my simple || doesn't compile, it gives me this error:

An exception occurred processing JSP page /sitemesh/main.jsp at line 7

Please help, thanks!


Indeed, string concatenation doesn't work that way in EL.

The following should work:

<c:set var="contextPath" value="${pageContext.request.contextPath}/" />
<c:set var="requestURI" value="${pageContext.request.requestURI}" />
<c:set var="isPeople" value="${fn:contains(requestURI, '/People/')}" />
<c:set var="isJobs"   value="${fn:contains(requestURI, '/Jobs/') || fn:endsWith(requestURI, contextPath)}" />

Note that I moved the trailing slash from the fn:endsWith to the <c:set value>.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜