#1. Dog dog = (Dog) getServletContext().getAttribute("dog");
Okay, so the above piece of code has nothing to do with listener. All it is trying to do is access the application scope variable(set by the listener).
#2. Dog dog = (Dog) getServletContext.getAttribute("dog");
A typo mistake; missed out the '()'; Sorry!
#3. 3 Scopes to Servlet. So, to access an application scope variable, we are using ServletContext instance. That's great.
#4. Dog dog = (Dog) getAttribute("dog");
In the above line, we are just trying to access the variable "dog" in request scope. // not "doing". typo mistake on your part.
Thanks for the reply, friend. Take Care.