javajspservletselscriptlet

Understanding how retrieving non-existing attributes with EL and JSP expression works. Inconsistency with Head First


There are two ways I can retrieve an attribute inside my JSP. Using JSP expressions or EL. What would happens if given attribute doesn't exist in those two cases? Let's try it (user doesn't exist):

<html><body>

--- <br>
<%=application.getAttribute("user") %>
<br>
--- <br>
${applicationScope.user}
<br>
---

</body></html>

OUTPUT:

 --- 
 null 
 --- 

 ---

What I understood from this is that EL gives empty space, while JSP expression gives NULL. But while reading Head First JSP and Servlets, I came across totally different explanation as stated in this screenshot. enter image description here

It says that they both give empty space, which as I showed isn't correct. Can someone guess what the case here is? I doubt they made such a mistake in well known book.


Solution

  • Books are written by people, and people make mistakes. You are correct in catching that. It should print null in the second example.

    As a matter of fact, there are a bunch of other errors in the book. In this case, the errata shows this:

    enter image description here