JSP 使用jstl el表达式判断session值

版权声明:《==study hard and make progress every day==》 https://blog.csdn.net/qq_38225558/article/details/85477858

maven项目中导入  jstl.jar 和 standard.jar 依赖包

 <!-- jstl.jar 和 standard.jar 【前端判断所需:<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>】-->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>
<dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
</dependency>

后端session存值

JSP页面中引入c标签

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

使用:

if 

<c:if test="${ sessionScope.avatar==null }">
    <a href="/login.html">登录</a>
</c:if>
<c:if test="${ sessionScope.avatar!=null }">
    <img src="${avatar}" alt="头像">
</c:if>

if-else

 <c:choose>
      <c:when test="${ sessionScope.avatar==null }">
          <a href="/login.html"></a>
      </c:when>
      <c:otherwise>
          <img src="${avatar}" alt="头像">
      </c:otherwise>
</c:choose>

猜你喜欢

转载自blog.csdn.net/qq_38225558/article/details/85477858
今日推荐