• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

invalid if{}else{} statements ??

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic