• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

invalid if{}else{} statements ??

 
Ryan Yeap
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
christine lorraine
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what happens if you remove the quotation marks in null?
isn't it that null is a literal in java?
 
Ryan Yeap
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic