You can't use "!=" or "==" to compare Strings.

http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html

You could use something like:

if (paramPassword.compareTo(secretCode) == 0) {

  // they match

} else {

  // they don't

}

Or flip your "if" around and use .equals():

if (paramPassword.equals(secretCode)) {

  // they match

} else {

  // they don't

}

So, in your current "if" statement, the condition is always true, as a FALSE
(that they match) condition can never happen.

John

> -----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 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 show that the two variables have the
> same value:
> 
> <!-- DEBUG FLAGS
> paramPassword: secret
>    secretCode: secret
> -->
> 
> What is going on?   Am I missing something obvious?
> 
> Thanks!
> 
> __________________________________________________
> Do you Yahoo!?
> Faith Hill - Exclusive Performances, Videos & More
> http://faith.yahoo.com
> 
> --
> To unsubscribe, e-mail:   
<mailto:tomcat-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail:
<mailto:tomcat-user-help@;jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@;jakarta.apache.org>

Reply via email to