15

How would I make the following code work?

        <c:if test="${null != searchResults}" >
            <c:forEach items="${searchResults}" var="result" varStatus="status">

I've tried many different variations of this, such as:

<c:if test="${searchWasPerformed}" >

or

<c:if test="<%=request.getAttribute("searchWasPerformed") %>" >

and even

<% boolean b = null != request.getAttribute("searchResults"); %>
    <c:if test="${b}" >

Which looks REALLY ugly :/ But I keep on getting the

org.apache.jasper.JasperException: /WEB-INF/jsp/admin/admin-index.jsp(29,2) PWC6236: According to TLD or attribute directive in tag file, attribute test does not accept any expressions

How would I go around this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Erik
  • 153
  • 1
  • 1
  • 4
  • your original code should work. What is the exception message for it? What is your JSP version? (and the version of tomcat, if you use it) – Bozho Sep 30 '10 at 11:52
  • The exception message was the one in the bottom of my post and the server I'm using is glassfish v3. :> As noted below, the problem was an outdated URI! Thanks again. – Erik Sep 30 '10 at 12:11
  • Good question! I had this exact problem happen to me yesterday. Now I can see that it was caused by me copy-and-pasting sample code from a forum post that was years old. – Jim Tough Sep 30 '10 at 12:21

1 Answers1

24

Check version of JSTL taglib you use. It should be 1.1, so you should have (note the URI):

<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
axtavt
  • 239,438
  • 41
  • 511
  • 482