This is the error I am receiving,
org.apache.jasper.JasperException: Unable to compile class for JSP: 
    An error occurred at line: 13 in the jsp file: /index.jsp
    Cannot cast from Object to boolean
This is my code:
Controller Servlet
if(authentication.verifyCredentials(request.getParameter("username"), 
   request.getParameter("password")))
{
        session.setAttribute("username", request.getParameter("username"));
        session.setAttribute("loggedIn", true);
        dispatcher.forward(request, response);   
}
I also tried this,
session.setAttribute("loggedIn", new Boolean(true));
JSP
<% 
    if(session.getAttribute("loggedIn") != null)
    {
        if(((boolean)session.getAttribute("loggedIn")))
        {
            response.sendRedirect("Controller"); 
        }
    }   
%>
Yes I researched and also saw the previous stackoverflow post; however I still cannot resolve my problem. Please assist.
boolean val = false; To convert it into an object, use the valueOf() method and set the argument as the boolean primitive. Boolean res = Boolean. valueOf(val);
You can cast DECIMAL values to BOOLEAN , with the same treatment of zero and non-zero values as the other numeric types. You cannot cast a BOOLEAN to a DECIMAL . You cannot cast a STRING value to BOOLEAN , although you can cast a BOOLEAN value to STRING , returning '1' for true values and '0' for false values.
Use the valueOf() method to convert boolean value to Boolean. Firstly, let us take a boolean value. boolean val = false; Now, to convert it to Boolean object, use the valueOf() method.
Unfortunately the compiler is not capable of deducing that the statement boolean var1=(var=null); would always lead to the invalid assignment boolean var1=null .
Try casting it to Boolean (nullable) instead of boolean in the JSP:
if(((Boolean)session.getAttribute("loggedIn")))
{
    response.sendRedirect("Controller"); 
}
                        try with
   if(((Boolean)session.getAttribute("loggedIn")))
instead of:
   if(((boolean)session.getAttribute("loggedIn")))
attribute has to be taken as Boolean, not as primitive type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With