Your message tells you what the problem is: java.lang.Character cannot be cast to java.lang.String
So the value of that attribute is of type Character
and thus casting that to String
of course will fail.
String.valueOf(...)
would help, but keep in mind that the result depends on the actual type, e.g. if the attribute was a string array, it would not work.
Addtionally, if(s.equals('0'))
would not work, since a string and character (which you get using the literal notation '0'
) are not equal.
In your case use one of the following:
Id' prefer this because there's no cast:
String s=String.valueOf( session.getAttribute("wrongP") );
if(s.equals("0")) { //use a String here
...
}
This should work as well, but would have the risk of another ClassCastException
it the type of the attribute changes:
Character c=(Character)session.getAttribute("wrongP");
if(s.equals('0')) {
...
}