简体   繁体   中英

Tag <c:if> doesn't work

I have method to get Cookies, and compare returned boolean with , but it doesn't work. Both condition doesn't work.

static public boolean isUserAuth(HttpServletRequest request){
        String cookieName = "forum_login";
        Cookie cookies [] = request.getCookies ();
        Cookie myCookie = null;
        if (cookies != null) {
            for (int i = 0; i < cookies.length; i++) {
                if (cookies[i].getName().equals (cookieName)) {
                    myCookie = cookies[i];
                    return true;
                }
            }
        }
        return false;
    }

JSP page:

<%@ page import="db_Proccesing.Users_processing" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    boolean test = Users_processing.isUserAuth(request);
%>

<!DOCTYPE html>

<header>
    <a class="header-logo"></a>

    <div id="form_text" class="form">
        <c:if test = "${test == true}">
        <p>TRUE</p>
        </c:if>
        <c:if  test = "${test == false}">
            <p>FALSE</p>
        </c:if>
    </div>
</header>

So, doesn't printed TRUE and FALSE

I fix it, using:

  <c:if test = "<%= !Users_processing.isUserAuth(request) %>">

Thank's all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM