wood burning stoves*
The moose likes Servlets and the fly likes invalid if{}else{} statements ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "invalid if{}else{} statements ??" Watch "invalid if{}else{} statements ??" New topic
Author

invalid if{}else{} statements ??

Ryan Yeap
Greenhorn

Joined: Apr 28, 2001
Posts: 28
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


<A HREF="http://www.mmorpgforums.com" TARGET=_blank rel="nofollow">An Online community for Online RPGs!</A>
christine lorraine
Greenhorn

Joined: Sep 03, 2001
Posts: 20
what happens if you remove the quotation marks in null?
isn't it that null is a literal in java?
Ryan Yeap
Greenhorn

Joined: Apr 28, 2001
Posts: 28
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 a .equals() instead of == "stringValue" method suggested by other person from another boards and it worked!
Thank you christine lorraine though
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: invalid if{}else{} statements ??