tags:

views:

68

answers:

1

Hi, 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 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!

+1  A: 

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

BalusC
Thanks a lot: this works, however it may affect further down in my code where the 'contextPath' variable gets used, which ideally i'd like to avoid.
Chris
You're welcome. You can set another variable for that :)
BalusC