"application" and "getServeltContext"

Lei Xiaowen

Greenhorn

Posts: 15

posted 11 years ago

Hi,All Can you tell me the difference between "getServletContext()" and "application"?

The code is as follows: ...... <%! public void jspInit() { getServletContext().setAttribute("cats",EShop.getCats())//why getServletContext() use here, and can we raplace it with application ? } public void jspDestroy(){........} %>

Correct me if I'm wrong, but aren't the implicit variables only declared for the _jspService() method? ie usable only in <% jsp code %> and <%= jspExpression %> This is code written in a <%! jsp declaration %> and so doesn't have access to the implicit variables. That would explain the call to getServletContext().

In fact to be completely compliant it should probably be getServletConfig().getServletContext(). The JSP interface doesn't mandate the implementation of the getServletContext() method. [ September 17, 2006: Message edited by: Stefan Evans ]