Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2002-07-29
7
Medium Priority
?
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 92

Accepted Solution

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

if (password.equals(conpass)) {
0
 

Author Comment

by:foongkim1
ID: 7187309
TQ.

0
 
LVL 92

Expert Comment

by:objects
ID: 7187337
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:foongkim1
ID: 7187541
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
ID: 7189294
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
ID: 7189369
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
ID: 7192148
Check for trailing spaces.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

688 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