can't find why loop don't go inside my condition in my java serrvlet -


@override protected void service(httpservletrequest request, httpservletresponse response)         throws servletexception, ioexception {     // todo auto-generated method stub     worlddbmanager db = new worlddbmanager();     string choices = request.getparameter("selectchoice");     list<worlpopulationinfo> country = new arraylist<>();      country = db.getresultasarraylist("world", "select * country");       stringbuffer strb = new stringbuffer();       for(int i=0;i<country.size();i++){         if(country.get(i).countryname == choices){             strb.append("<option selected='selected'>" + country.get(i).countryname+"</option>");             system.out.println(choices + " pareil " + country.get(i).countryname);         }else if(country.get(i).countryname != choices){             strb.append("<option>" + country.get(i).countryname+"</option>");             system.out.println(choices + " " + country.get(i).countryname);         }     }       request.setattribute("country", strb);         getservletcontext().getrequestdispatcher("/index.jsp").forward(request,  response);  } 

i don't understand why doesnt go first if condition know value variable choices exist inside database doing system.println. don't understand why ignoring equality. if explain me im doing wrong. thank.

try -

if(country.get(i).countryname.equals(choices)){ 

you don't need else if there, else sufficient

 if(country.get(i).countryname.equals(choices)){             strb.append("<option selected='selected'>" + country.get(i).countryname+"</option>");             system.out.println(choices + " pareil " + country.get(i).countryname);         }else{             strb.append("<option>" + country.get(i).countryname+"</option>");             system.out.println(choices + " " + country.get(i).countryname);         } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -