ServletConfig, ServletContext, ServletContextListener
ServletConfig, ServletContext, ServletContextListener
- ServletConfig
o Values are only accessible to one servlet per servletConfig
o Can have one servletConfig per Servlet
o Let’s say you have 10 servlets then you could have 10
servletConfigs
o <init-param>
o Can only handle values that are Strings
o Retrieving data with the use of getInitParameter
- ServletContext
o Values are accessible to the whole web application including JSP’s
and Servlets
o It is like a static variable in java
o Used usually when creating Header and Footer
o <context-param>
o Can only handle values that are Strings
o Retrieving data with the use of getInitParameter
ServletContextListener
- Is called when the web application is first created
- Needs to be implemented in order to be used
- A class or model is needed for it to be used, the class contains 2
methods: contextInitialized and contextDestroyed
- <listener>
- Handle values like objects that you want to share to the whole web
application
- -Servlets then are used as a controller to pass the object value around
the web application
- ServletContextEvent is used as a notification of ServletContextListener
when values are pass of ServletConfig and ServletContext