Evaluate list.contains string in JSTL

后端 未结 10 1186
青春惊慌失措
青春惊慌失措 2020-12-07 14:08

I need to hide an element if certain values are present in the JSP

The values are stored in a List so I tried:



        
10条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 14:53

    I found this solution amazing.

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
    <%
       ArrayList list = new ArrayList();
       list.add("one");
       list.add("two");
       list.add("three");
    %>
    
    
    
            My list is ${list}
    My list contains two
    My list contains ,

    The output for the code above is

    My list is [one, two, three]

    My list contains two

    My list contains ,

    I hope it helps someone.

提交回复
热议问题