簡體   English   中英

標簽 <c:if> 不起作用

[英]Tag <c:if> doesn't work

我有方法來獲取Cookies,並將返回的布爾值與進行比較,但是它不起作用。 兩種情況都不起作用。

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

我使用以下方法修復它:

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

謝謝大家

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM