This is a Java programming language issue, not a JSP issue. A String in
Java is an object. Both a variable containing a string and a literal
string are actually "references" to an object (instanceof String class)
which object contains the actual string itself. The == operator compares
the object references to each other, and will not evaluate to true
unless the two objects are the same object. The equals() method of the
String class compares the two strings character by character.
Suppose s and t are both strings containing "abc". Then,
s == t may be false, but
s.equals(t) is true, as is t.equals(s)
after the assignment
s = t; then, s == t would be true because both s and t REFER TO
the same object
Hope this helps,
Bruce Conrad
-----Original Message-----
From: Chris Mcgarel [mailto:[EMAIL PROTECTED]]
Sent: Friday, August 27, 1999 9:42 AM
To: [EMAIL PROTECTED]
Subject: JSP Form
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