@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 * from 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);
}
我不明白为什么他不去第一个如果条件我知道变量选择的值存在于我的数据库中,通过执行 System.println。我只是不明白为什么无视我的平等。如果有人可以解释我做错了什么。谢谢。