Why requestScope is null and not null at the same time? this is part of a code of index.jsp file
<c:if test="${!pageContext.request.servletPath.equals('/Login')}">
<c:if test = "${requestScope.Cars!=null}">
<%
List<Car> cars = (ArrayList<Car>)request.getAttribute("Cars");
System.out.println(cars.get(0));
%>
</c:if>
<c:if test="${requestScope.Cars==null}">
<%
System.out.println(request.getAttribute("Cars")+" test");
%>
<jsp:forward page="/AllCarCategories"/>
</c:if>
</c:if>
the first if statement was just to check how it can be null and not null at the same time
this is what AllCarCategories looks like
@WebServlet(name = "AllCarCategories", urlPatterns = {"/AllCarCategories","/Login/AllCarCategories"})
public class AllCarCategories extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
MySQLDAOFactory dao =(MySQLDAOFactory) DAOFactory.getDAOFactory(1);
MySQLCarDao carDao = (MySQLCarDao) dao.getCarDao();
MySQLCarCategoryDao categoryDao = (MySQLCarCategoryDao)dao.getCarCategoryDao();
List<CarCategory> carCategories = categoryDao.findAllCarC();
List<Car> cars = carDao.findAllCars();
System.out.println(carDao.findAllCars().size()+" size ");
request.setAttribute("Cars",cars);
request.setAttribute("Categories",carCategories);
request.setAttribute("ImageMan", ImageManager.getInstance());
System.out.println("request url:" +request.getRequestURL()+" requst servlet Path"+request.getServletPath());
request.getRequestDispatcher("index.jsp").forward(request,response);
}
}
so at first time when its null im forwarding it to AllCarCategories and there list of Car objects is created, then im forwarding it to jsp file and by logic it cant be null because i created a List of Car objects but it is And another mystery is that its enters in both if statements so its null and not null at the same time
this is what console outpuut looks like(Just to show what is going on there)

How it can be null and not null at the same time?Thanks
add an additional print before the first
iftesting fornull(eventually one after secondif) like(just to show a bit more of information, not a real answer, and I do not develop JSP)