Solved

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

Posted on 2002-07-29
7
184 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 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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 Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
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.
Suggested Courses

615 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