Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jsp

jstl

el

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?

like image 939
Erik Avatar asked Sep 30 '10 11:09

Erik


People also ask

Which of these is a valid JSTL if tag?

The < c:if > tag is used for testing the condition and it display the body content, if the expression evaluated is true. It is a simple conditional tag which is used for evaluating the body content, if the supplied condition is true.

Why is JSTL not working?

All you need to do is: Download the zip, extract it, open its /lib folder and copy jstl. jar and standard. jar files in /WEB-INF/lib folder (thus, not /lib ) of your webapp.

How check list is empty or not in JSTL?

The first way is to use the JSTL tag and empty operator to check if an ArrayList is empty and the second way is to use the JSTL function, fn: length() instead of the empty operator as shown in our example.

Which tag is used in JSTL to show the output?

The <c:out> tag is similar to JSP expression tag, but it can only be used with expression. It will display the result of an expression, similar to the way < %=... % > work.


1 Answers

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" %>
like image 63
axtavt Avatar answered Sep 20 '22 23:09

axtavt