Shawn,
Just to clarify - your code snippet is very misleading. The reason
<c:if test="${a == b}"> evaluates to true is because null == null, not
because "a == b" where a = "foo". a & b are not in any scope so in the
EL, a & b are null - in fact it doesn't matter what you set a or b to.
Changing your example a little:
<%
String s1 = "string1";
String s2 = "string2";
%>
s1 = <c:out value="${s1}"/>, s2 = <c:out value="${s2}"/>,
<c:if test="${s1 == s2}">s1 == s2</c:if>
Surprisingly, you'll see "s1 == s2" on the output. Of course you'll
also see from the line above that "s1 = , s2 = ", that is, you're
referencing bogus variables.
Anyways- thought I would clarify for other users out there.
This does point out a danger in the test= stuff, since you reference
bogus variables without error, you may not be actually testing what you
think you're testing.
Let me know if I'm incorrect.
Thanks,
Glenn
On Tue, 2002-04-09 at 09:57, Shawn Bayern wrote:
> Are you sure the strings are really identical? For instance, just to be
> sure you're using two different Strings with the same value, you can
> experiment via the String copy constructor. Doing this demonstrates that
> JSTL's '==' operator does work correctly:
>
> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/ea/core" %>
>
> <%
> String a = "foo";
> String b = new String(a);
> %>
>
> <c:if test="${a == b}">
> a indeed equals b
> </c:if>
>
> Make sure that the two strings in your database don't have different
> amounts of whitespace, are indeed of the same case (uppercase, lowecase,
> etc.), and so on. I often find it useful to print out values with a
> marker (e.g., the ' character) on both sides to make sure I'm not missing
> any whitespace.
>
> --
> Shawn Bayern
> Author, "JSP Standard Tag Library" http://www.jstlbook.com
> (coming this summer from Manning Publications)
>
> On Tue, 9 Apr 2002, marba wrote:
>
> > I'm try to compare two string fields in a MySql table row
> > here's my code that evaluate false even if the strings are identical:
> >
> > <sql:query var="filiali" dataSource="${ds}">
> > SELECT * FROM FILIALI_EXT_LOG LEFT JOIN FILIALI_EXT USING (ID)
> > WHERE FILIALI_EXT_LOG.LASTMODI > <c:out
> > value="${user.lastTimeStamp}"/>
> > </sql:query>
> >
> > <c:forEach var="row" items="${filiali.rows}">
> > <c:set var="campi" value="51"/>
> > <c:forEach var="i" begin="0" end="${campi}">
> >
> > <c:if test="${row.columns[i] == row.columns[i]}">
> > evaluates true OK
> > </c:if>
> >
> > <c:if test="${row.columns[i] == row.columns[i+campi]}">
> > evaluates false even if Strings are identical
> > </c:if>
> >
> > Thank You
> >
> >
> >
> > --
> > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> >
>
>
> --
> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>