开发者

${form.test} prints "var", but ${form.test== 'var'} is always false

开发者 https://www.devze.com 2023-03-30 18:13 出处:网络
when I tried to print a value in JSP, it\'s print开发者_Python百科ing 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 s

when I tried to print a value in JSP, it's print开发者_Python百科ing 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 */


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" %>


Try:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号