Question

I am experiencing some strange issues with request.getParameter("param") in Java. I am trying to test the returned value to set a boolean, nothing fancy. :)

String param = String.valueOf(request.getParameter("param"));
boolean paramIsAll = false;
if (param == "all"){paramIsAll = true;}

System.out.println("-"+ param +"-"+ String.valueOf(paramIsAll));

My output is: -all-false

???

Était-ce utile?

La solution

try with if (param.equals("all")){paramIsAll = true;}

while comparing 2 strings use String#equals()

Autres conseils

Try: If(param.equalsIgnoreCase("all")){paramIsAll = true;}

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top