${form.test} 打印“var”,但 ${form.test== 'var'} 始终为 false

发布于 2024-12-01 09:21:20 字数 290 浏览 0 评论 0原文

当我尝试在 JSP 中打印一个值时,它打印名为 "var" 的值,但是当我尝试在 if 条件中使用相同的值时,它似乎不起作用。请有人帮助我...:(:(

<c:out value="${form.test}" /> /* for printing and it's printing "var"*/
<c:if test="${form.test== 'var'}"> /* for if condition which is not working */

when I tried to print a value in JSP, it's printing the value which is named "var" but when I tried to use the same value in a if condition it doesn't seem to be working. Please somebody help me...:(:(

<c:out value="${form.test}" /> /* for printing and it's printing "var"*/
<c:if test="${form.test== 'var'}"> /* for if condition which is not working */

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷你仙 2024-12-08 09:21:20

它应该可以正常工作,假设这些双引号不是值的一部分(即您看到的是 var,而不是 "var")。也许该值周围有一些悬空的空白?

您可以通过以下方式调试其中一种或另一种:

<pre>|<c:out value="${form.test}" />|</pre> <!-- Should print |var| -->

<c:out value="${fn:length(form.test)}" /> <!-- Should print 3 -->

确实是空格并且您无法在 servlet/SQL 端修剪它,请考虑使用 fn:trim()

<c:if test="${fn:trim(form.test) == 'var'}">

如果 “http://download.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/fn/tld-summary.html”rel="nofollow">JSTL 函数 标签库可以通过以下方式获得:以下标记库声明:

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

It should work fine, assuming that those doublequotes are not part of the value (i.e. you're seeing var, not "var"). Perhaps there's some dangling whitespace around the value?

You could debug the one and other the following ways:

<pre>|<c:out value="${form.test}" />|</pre> <!-- Should print |var| -->

and

<c:out value="${fn:length(form.test)}" /> <!-- Should print 3 -->

If it is indeed the whitespace and you cannot trim it in the servlet/SQL end, consider using fn:trim():

<c:if test="${fn:trim(form.test) == 'var'}">

The JSTL functions taglibrary is by the way available by the following taglib declaration:

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
献世佛 2024-12-08 09:21:20

尝试:

<c:if test="${form.test eq 'var'}">

Try:

<c:if test="${form.test eq 'var'}">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文