In the below Java code which is placed in a JSP file,
if (false == session.getAttribute("loggedin")) {
response.sendRedirect("login.jsp");
}
else if (null == session.getAttribute("loggedin")) {
response.sendRedirect("login.jsp");
}
I am getting the following compilation error:
incompatible operand types and object
How is this caused and how can I solve it?
session.getAttribute()returns an Object. An Object can’t be compared to a boolean. So the expressionfalse == session.getAttribute("loggedin")is invalid. If you want to check ifBoolean.FALSEis stored in the session attribute, the code should beNote that you’d better put all the Java code in regular Java classes and limit yourself to the JSP EL in the JSPs. Scriptlets should not be used anymore.