简体   繁体   English

消息字符串为空时如何隐藏 div? (特别是:SPRING_SECURITY_LAST_EXCEPTION.message)

[英]How can I hide a div when the message string is empty? (specifically: SPRING_SECURITY_LAST_EXCEPTION.message)

I have a web app built with Bootstrap 3 and Java / Spring MVC.我有一个使用 Bootstrap 3 和 Java / Spring MVC 构建的 web 应用程序。

I'm building a custom login form page for Spring Security.我正在为 Spring Security 构建一个自定义登录表单页面。

Works fine except this part where the error message box is always displayed even when the error message is empty string...工作正常,除了这部分错误消息框总是显示,即使错误消息是空字符串......

<c:if test="${SPRING_SECURITY_LAST_EXCEPTION.message ne ''}">
    <div id="dangerAlert" class="alert alert-danger" >
        ${SPRING_SECURITY_LAST_EXCEPTION.message}
    </div>
</c:if>

How can I check if this string ${SPRING_SECURITY_LAST_EXCEPTION.message} is empty and hide the div?如何检查此字符串${SPRING_SECURITY_LAST_EXCEPTION.message}是否为空并隐藏 div?

Answering my own question (and thanks to @Rajeev for pointing me a good direction that helped).回答我自己的问题(感谢@Rajeev 为我指出了一个有帮助的好方向)。

This works...这有效...

<c:if test="${not empty SPRING_SECURITY_LAST_EXCEPTION.message}">
    <div id="dangerAlert" class="alert alert-danger" >
        ${SPRING_SECURITY_LAST_EXCEPTION.message}
    </div>
</c:if>

NOTE: Don't forget to import the correct tag lib in your JSP like I did forgot to do...注意:不要忘记在 JSP 中导入正确的标签库,就像我忘记做的那样......

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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