|
-
Sep 3rd, 2001, 10:20 PM
#1
Thread Starter
Member
if{}else{} statements error?
I'm having a problem with this section of my forms processing.
its a jsp form which , when submitted passes the values to another jsp page that processes and outputs the results.
Heres the block of code that is giing me the problem:
----------------------------------------------------------------
String typeCombo = request.getParameter("typecombo");
String modelCombo = request.getParameter("modelcombo");
String brandCombo = request.getParameter("brandcombo");
if(modelCombo == "null" && brandCombo == "null" && typeCombo != "null"){
SQLString = "select * from s99661251_Products WHERE type = '" + typeCombo + "'";
showResult(out, request, SQLString);
}
else if(typeCombo == "null" && brandCombo == "null" && modelCombo != "null"){
SQLString = "select * from s99661251_Products WHERE model = '" + modelCombo + "'";
showResult(out, request, SQLString);
}
else if(typeCombo == "null" && modelCombo == "null" && brandCombo != "null"){
SQLString = "select * from s99661251_Products WHERE brand = '" + brandCombo + "'";
showResult(out, request, SQLString);
}
else if(modelCombo == "null" && brandCombo != "null" && typeCombo != "null"){
SQLString = "select * from s99661251_Products WHERE type = '" + typeCombo + "' AND brand = '" + brandCombo + "'";
showResult(out, request, SQLString);
}
else if(typeCombo == "null" && brandCombo != "null" && modelCombo != "null"){
SQLString = "select * from s99661251_Products WHERE model = '" + modelCombo + "' AND brand = '" + brandCombo + "'";
showResult(out, request, SQLString);
}
else if(brandCombo == "null" && modelCombo != "null" && typeCombo != "null"){
SQLString = "select * from s99661251_Products WHERE type = '" + typeCombo + "' AND model = '" + modelCombo + "'";
showResult(out, request, SQLString);
}
else if(typeCombo == "null" && brandCombo == "null" && modelCombo == "null"){
//showComboError = "<font color=red>You need to select at least one critiria!</font>";
}
else{
SQLString = "select * from s99661251_Products WHERE type = '" + typeCombo + "' AND model = '" + modelCombo + "' AND brand = '" + brandCombo + "'";
showResult(out, request, SQLString);
}
--------------------------------------------------------------
where typeCombo, modelCombo, brandCombo will provide a "null" String value if the user does not choose anything from the combobox. Yes, the form just consists of 3 combo boxes.
The problem is, the process seems to always skip to the else{} statement. ignoring the previous if{} and elseif{} statements. What is it that I am doing wrong? (also if i try removing the else statement altogether, the form does not even process)
Thanks.
Ryan
-
Sep 3rd, 2001, 10:57 PM
#2
well, #1, you don't put ""'s around null. You just say null. And #2, if you are going to do a String comparision, you can't say
if("Hello" == strHello)
because that statement is testing whether the two Strings are pointing to the same address in memory. You have to use String's equals() method
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Sep 4th, 2001, 12:39 AM
#3
Thread Starter
Member
Opps, maybe I should have clearified that the form sends a String value "null" to the jsp and not a default null value itself, but that doesnt matter.
I used the .equals() you suggested and it worked like a charm!
tHanks!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|