标记<c:if>不起作用</c:if>

时间:2015-03-08 23:09:36

标签: java jsp jstl

我有获取Cookie的方法,并将返回的布尔值与之比较,但它不起作用。这两种情况都不起作用。

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 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>

所以,不打印TRUE和FALSE

1 个答案:

答案 0 :(得分:0)

我修复它,使用:

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

谢谢所有人。