How to use the JSTL "if" tag without getting "..attribute test does not accept any expressions" [duplicate]
Asked Answered
V

1

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?

Villanueva answered 30/9, 2010 at 11:47 Comment(3)
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)Tripping
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.Villanueva
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.Mariselamarish
D
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" %>
Depreciatory answered 30/9, 2010 at 11:54 Comment(2)
Thank you both, the URI seems to have been an old one: java.sun.com/jstl/coreVillanueva
@Erik: That's the JSTL 1.0 URI. This doesn't go well with JSP 2.0 as you encountered.Blackthorn

© 2022 - 2024 — McMap. All rights reserved.