Search code examples
javajspif-statementjstljsp-tags

JSTL if tag always execute as true


I am working with a JSTL and trying to implement a if tag

below is my code for file login.tag

<c:if test="${not empty param.error}">
        //do something
</c:if>

My understanding is when I access this page

with path/index.jsp   //the if tag is not executed 
with path/index.jsp?error=wrongpassword   //the if tag is executed

But what I am getting now is the if tag is always execute true, Please advice


Solution

  • If you want to use c:if tag you should use JSP taglib directive for JSTL core tag library. Use below code at the top of the JSP

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    

    You also need libraries for JSTL as dependencies to your project. See this answer to find maven dependencies.