This is because strings are objects.  The double equals compares if the are the
same object rather than if the values of the objects equals (like .equals())

Carl

Chris Mcgarel wrote:

> Can someone expalin to a novice why I must use:
>          if (Request.Form("myFormElement").equals("myString"))
> rather than a straight comparison operator:
>         if (Request.Form("myFormElement")=="myString")
> ?
>
> The latter does not work for me even though both left and right sides of the
> statement are Strings.
>
> The full code for form.jsp is:
>
> <body>ody bgcolor=darkblue text=white>
> <font face=arial>
> <%
>     String myTest = "";
>
>     myTest = Request.Form("mySubmit");
>
>     if (myTest=="Click")                        // doesn't work, must be if
> (myTest.equals("Click"))
>     {
>         out.println ("CLICKED!!!");
>     }
>
> %>
>
> <form action="form.jsp">
> <input type=submit name="mySubmit" value="Click">
> </form>
>
> </font>
> </body>
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> FAQs on JSP can be found at:
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to