javascript - jsp 页面中的 jSTL 标记中的 if else

标签 javascript jsp session jstl

<div align="right">
     <b> Connected:</b> <%=(String)session.getAttribute("CONNECTION_DBNAME")%>
     </div>
  • 我在jsp页面中有上述代码
  • 最初 session CONNECTION_DBNAME 没有任何值。
  • 当CONNECTION_DBNAME为空时,我需要显示未连接
  • 当 CONNECTION_DBNAME 具有值时,会打印某些值。
  • 我知道可以通过使用带有条件的 if else 来实现,但我不知道如何在 jSTL 标记内使用 if else 。

最佳答案

<c:if test="${sessionScope.CONNECTION_DBNAME!= null}"> 
 Connected:${sessionScope.CONNECTION_DBNAME}
</c:if>
<c:if test="${sessionScope.CONNECTION_DBNAME== null}"> 
 NOT CONNECTED
</c:if>


  or 


<c:choose>
 <c:when test="${sessionScope.CONNECTION_DBNAME != null}">
   Connected:${sessionScope.CONNECTION_DBNAME}
 </c:when>  
 <c:otherwise>
  NOT CONNECTED
 </c:otherwise>
</c:choose>

关于javascript - jsp 页面中的 jSTL 标记中的 if else,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15132526/

相关文章:

javascript - Bootstrap 模态框无法打开

python - 将 python session 传递给用另一个版本的 python 编写的脚本

php - 如何在登录脚本中使用 session

javascript - jQuery 测试表单字段是否不为空

javascript - 主干 - 无法读取未定义的属性 'get'

php - 表单困难时的多个提交按钮

javascript - 如何将固定宽度和 "custom-resizeable"长度设置为 Spring <form :textarea/>?

java - Servlet 未调用

jsp - Tomcat开发模式下重新加载JSTL Tag文件

php - 将 HTML 表单值作为数组放入 SESSION 变量中