Solved

If....else...... end.

Posted on 2002-07-29
7
177 Views
Last Modified: 2010-03-31
Hi friend, here is the funny question. I have 2 variable, password and conpass, I need to make sure these 2 variable is the same value before I can process. What I have done is like below:

a.jsp
=====
<html>
<head>
...............
...............
...............

 <%
   String username = request.getParameter("username");
   String password = request.getParameter("password");
   String conpass = request.getParameter("conpass");
   
   out.println(password);
   out.println(conpass);
   
  if (password == conpass) {

           wasusr.connect();
        wasusr.insert(username,password,conpass);
        out.println("Registration Completed !!");
   } else {
        out.println("Make Sure it;s the same!!");
   }
             
  %>

When I out print the variable, it's shown both variable is the same but the statement, "Make Sure it's the same" prompt out also.

Any ideas??

I have odne some comparison before for "String", proven it's working for String also .
Please help.
0
Comment
Question by:foongkim1
  • 4
  • 3
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
Comment Utility
== tests if they are the same object.
To test string equality use the equals() method:

if (password.equals(conpass)) {
0
 

Author Comment

by:foongkim1
Comment Utility
TQ.

0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:foongkim1
Comment Utility
objects, so sorry to recall this again.

My below code doesn't performt the comparison purpose?
Why?

***************
String username=request.getParameter("username");
String password=request.getParameter("password");

wasusr.connect();
ResultSet rs = wasusr.checkusr(username);

  if (rs.next()) {
     String checkpass = rs.getString("WA1002");
     out.println(username);
     out.println(password);
     out.println(checkpass);
     
     if (checkpass.equals(password)) {
 out.println("Compare OK!");
}
}

it's doesn't print out the "Compare OK!", not event perform the compare statemet (IF). Further more, WA1002, is a CHAR in database.....

pleaseeeee

0
 
LVL 92

Expert Comment

by:objects
Comment Utility
the i'd say they aren't equal.
Print the value of the two strings to check. Maybe there are trailing spaces on one.
0
 

Author Comment

by:foongkim1
Comment Utility
if (rs.next()) {
    String checkpass = rs.getString("WA1002");
    out.println(username);
    out.println(password);
    out.println(checkpass);

this statement already printed out and it's shown the value is the same.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
Check for trailing spaces.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now