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
Solved

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

Posted on 2002-07-29
7
181 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
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
diffSum example 4 50
servlet example 11 49
Java Eclipse Loop 3 20
What browser will run Java? 7 41
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

792 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