No NullPointerException in JSTL when calling methods on a null object associated with request object.why?

Yesterday I appeared in an interview. The interviewer shows me this code and asked -

<c:when test='${hobby.equals("hobby1")}'> 

Why there is no null pointer and the hobby value is null

The code is -

In the Sevlet class -

 request.setAttribute("hobby", null); request.getRequestDispatcher("display.jsp").forward(request, response); 

In display.jsp -

 <c:when test='${hobby.equals("hobby1")}'> 
+6
source share
1 answer

JSTL almost always suppresses NullPointerExceptions. There is a brief discussion here and can be found in more detail in section 3.6 of the JSTL specification .

+9
source

Source: https://habr.com/ru/post/988436/


All Articles