• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

"application" and "getServeltContext"

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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(){........}
%>

--------
Best wishes,
LeiXiaowen
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no difference.

The implicit variable "application" is there for convenience so you don't need to call getServletContext().
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good point.
The implicit variables are not available in outside of the service method.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic