-
From: Z.BEAT [mailto:zackbeatty;yahoo.com]
Sent: Thursday, October 17, 2002 1:58 PM
To: Tomcat Users List
Subject: expression ALWAYS evaluates to if... NEVER to else
In the following code snippet, the expression ALWAYS
evaluates to the if statement block:
String paramPassword =
request.getParameter
1:58 PM
To: Tomcat Users List
Subject: expression ALWAYS evaluates to if... NEVER to else
In the following code snippet, the expression ALWAYS
evaluates to the if statement block:
String paramPassword =
request.getParameter(paramPassword);
String secretCode = secret;
if(paramPassword
Hello Z.BEAT,
If these are both java String objects then all you are comparing is if
the memory location of string object #1 is the same as that of String
object #2. This is probably not true. You need to compare like this.
if (paramPassword.equals(secretCode)) {
} else {
}
You can only
You need to learn how java compares objects and strings. The short story is:
if(!paramPassword.equals(secretCode))
{
}
else
{
}
-Original Message-
From: Z.BEAT [mailto:zackbeatty;yahoo.com]
Sent: 17 October, 2002 11:58 AM
To: Tomcat Users List
Subject: expression ALWAYS evaluates
: expression ALWAYS evaluates to if... NEVER to else
Hello Z.BEAT,
If these are both java String objects then all you are comparing is if
the memory location of string object #1 is the same as that of String
object #2. This is probably not true. You need to compare like this.
if (paramPassword.equals
information on the equals and
equalsIgnoreCase methods.
Steve
-Original Message-
From: Z.BEAT [mailto:zackbeatty;yahoo.com]
Sent: Thursday, October 17, 2002 1:58 PM
To: Tomcat Users List
Subject: expression ALWAYS evaluates to if...
NEVER to else
In the following code
In the following code snippet, the expression ALWAYS
evaluates to the if statement block:
String paramPassword =
request.getParameter(paramPassword);
String secretCode = secret;
if(paramPassword != secretCode)
{
}
else
{
}
However, my debugging flags that I send in an HTML
comment CLEARLY