开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜