if (session.get("bla") == "test开发者_JAVA百科") {} // is always false wether it is "test" or not
if (session.get("bla") == null) {} // works if it is null
I'm not sure what the problem is but in my 1.2.2 installation I'm not able to compare
Comparing objects with ==
is comparing the objects' references, which means that two strings with identical values might not be the same object. In order to compare the string values, use equals
.
if (session.get("blah").equals("test")) {}
I refer you to the Java documentation for String.
精彩评论