【问题标题】:JSTL if tag always execute as trueJSTL if 标记始终执行为 true
【发布时间】:2014-12-25 13:07:42
【问题描述】:

我正在使用 JSTL 并尝试实现 if 标记

下面是我的文件login.tag的代码

<c:if test="${not empty param.error}">
        //do something
</c:if>

我的理解是当我访问这个页面时

with path/index.jsp   //the if tag is not executed 
with path/index.jsp?error=wrongpassword   //the if tag is executed

但是我现在得到的是if标签总是执行true,请指教

【问题讨论】:

  • 检查生成的 HTML 代码。我的猜测是它包含,这意味着if标签没有被解释,可能是因为你没有在JSP的顶部声明代码库。
  • 我检查了 html , c:if 打印在 html 中,这是什么意思?
  • 表示if标签没有被解释,可能是因为你没有在JSP的顶部声明代码库。

标签: java jsp if-statement jstl jsp-tags


【解决方案1】:

如果你想使用c:if 标签,你应该使用JSP taglib 指令作为JSTL 核心标签库。在 JSP 的顶部使用下面的代码

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

您还需要 JSTL 库作为项目的依赖项。请参阅this 答案以查找 maven 依赖项。

【讨论】:

  • 感谢您提到添加依赖项,终于让它按预期工作!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-28
  • 1970-01-01
相关资源
最近更新 更多