Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7442535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:11:18+00:00 2026-05-29T11:11:18+00:00

I am having a problem with JSTL and empty operator. I already made few

  • 0

I am having a problem with JSTL and empty operator. I already made few simple pages and everything worked fine, but now I have:

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <html>
    <body>

     <form action="/Projekt/myaccount" method="post">
    <table border="1">
        <tr>
                 <td>Artist</td>
                 <td>Record Name</td>
                 <td>Delete</td>
         </tr>
        <c:forEach var="item" items="${records}">
         <tr>
                 <td>${item.artist}</td>
                 <td>${item.recordName}</td>
                 <td>
                    <input type="checkbox" name='${item.recordName}|${item.recordName}'/>
                 </td>
         </tr>
        </c:forEach>
    </table>
    <hr/>
        <input type="submit" name="back" value="back"/>
        <c:if test='${not empty "${records}"}'>
               <input type="submit" name="delete" value="delete selected"/>
        </c:if>
     </form>
    </body>
    </html>

now no matter if I set the records attribute or not, the delete button shows up:

<c:if test='${not empty "${records}"}'>
           <input type="submit" name="delete" value="delete selected"/>
    </c:if>

in normal situation to records attribute I pass ArrayList and then use foreach, but sometimes ArrayList is empty, so in those situations I don’t want delete button to show up, I fought that easiest way to achieve this would be to use this empty operator. Where am I making a mistake?

I even tried to manually set this attribute to null:

if (ar.size() != 0)
    request.setAttribute("records", ar);
else
    request.setAttribute("records",null);

EDIT:
@Qwe: yes you are right, it worked for me before because I tested if attribute was empty in my way, it was always true, because I used wrong construct, but it worked because I just wanted to show one string, if there was no String nothing showed up so I was thinking that everything worked fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:11:19+00:00Added an answer on May 29, 2026 at 11:11 am

    <c:if test='${not empty "${records}"}'> as well as <c:if test="${!empty '${showWarning}'}"> (from your comment) will always resolve to true because you’re are actually testing if a String ${records} is empty or not, and obviously it is not.

    Just to be sure – by String ${records} I mean a String value, just as if you were assigning it in Java like String foo = "${records}";.

    The next line of code will test if records variable (that is looked up from page, request, session or application scope) is empty or not:

    <c:if test="${not empty records}">
    

    The line of code is 100% guaranteed to work 🙂

    Also, request.setAttribute("records",null) is a bad way to remove attributes because empty tests not just request scope, but page, session etc. Use <c:remove var='records'/> instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with JSTL formatDate when displaying dates from MySQL database. I
I am having problem when running my simple JSF hello-world like web app. The
Im having problem in importing hotmail contacts from hotmail in php it simple give
I'm having problem with a copying method in a simple C++ program. Everytime I
Am having problem in using simple date format for this: having date as 12/13/2011
having problem with null pointer exception and i read few article bout that error
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
We're having problem with a huge number of legacy stored procedures at work. Do
I'm having problem in the following line: rd.PrintOptions.PaperSize = PaperSize.PaperFanfoldStdGerman; it throws an exception
We are having problem with the server migration. We have one application that are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.