='s tests object equality, .equals tests content equality...

so the first test looks to see if the two strings contain the same characters,
the second test looks to see if the two strings are the same String object...

Just to make sure that it is confusing, you can make strings resolve to the same
object by interning them...
so you could do this:

String s = Request.Form("myFormElement");
s.intern();
if (s=="myString") {
  // Do something
}

-gabe


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