This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JSP and the fly likes Diffenrence between application and servletConfig - servletcontext Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Diffenrence between application and servletConfig - servletcontext" Watch "Diffenrence between application and servletConfig - servletcontext" New topic
Author

Diffenrence between application and servletConfig - servletcontext

Fouad Fares
Ranch Hand

Joined: Apr 16, 2003
Posts: 38
Hello,
I want to clarify the difference between using application objects [getattribute - setattribute] and the servletconfig - servletcontext objects.
Please note that in my web application i create an init class called from the web.xml this class implement the servletcontextListener like the following code :
=======================
public class Jcls_Init implements ServletContextListener
{
public void contextInitialized(ServletContextEvent sce)
{
sce.getServletContext().setAttribute("config","1");
}
}
------------------------
And to retrive this value in my jsp page i write the following code :
String s_val = (String)getServletConfig().getServletContext().getAttribute("config") ;
=========================
Questions :
1- Is this king of coding are storing the value
of config variable in the memory once we start the application
through the Oracle Entreprise manager ?
2- Is the value of config variable persist as long as the application [oc4j]
is up and running .
3- What is the difference between the above code and the application.getAttribute and application.setattribute.
Best Regards.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56216
    
  13

The "application" variable exposed in JSP pages stores its variable in the servlet context. For the purposes of scope variables, they are one and the same.
Once set into application context, the variable will remain there until explicitly removed or the application itself is removed.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Fouad Fares
Ranch Hand

Joined: Apr 16, 2003
Posts: 38
Hello,
As i understand that the application and servletcontext are the same.
and the variable of type application are initialised once starting the web application through the Oracle entreprise manager and it will be remove from memory once stopping the web application .
Best regards,
Fouad
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Diffenrence between application and servletConfig - servletcontext
 
Similar Threads
Configure Portlet request attributes for Weblogic 10.2
Servlet concepts doubts
application scope in servlet
Object through out application
My example with ServletContextListener and ServletContextAttrib.