Professional Documents
Culture Documents
1. Accessed by servlet
i. servlet init parameters(inside <servlet> in DD)
ii. Accessed via ServletConfig
out.println(getServletConfig().getInitParameter());
<web-app>
<servlet>
<servlet-name></servlet-name>
<servlet-class></servlet-class>
<init-param>
<param-name></param-name>
<param-value></param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name></servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>
</web-app>
1. u cant access init parameters unless the servlet is initialized i.e not iside
constructor.
2. The container reads the init parameters from the DD and gives them to
ServletConfig and passes ServletConfig to servlet init method.
3.init parameters r read once when container creates a servlet.
4.so if u want to change them u have to redeploy.
5. hot deploy comes to rescur.if u simply redeploy all apps go down which is bad on
production so better option is hot redeploy which redeploys only one particular
app.Its there on tomcat also.
6.In the real world even hot deploy can take a lot of time.
Similarly ServletContext is created except that the name value pairs are created
first and then the ServletContext is created.Servlet Context is created when the web
app is deployed.
--------------------------------------------------------------------init();
init(ServletConfig servletconfig);(calls the no-arg version)
One servletContext per web-app and one ServletConfig per servlet or JSP
If the app is distributed there is one ServletContext per JVM
For storing info used by complete app like database look up names
this.getServletContext().getInitParameter();
8 kinds of listeners :
1. When theres a lifecycle moment theres a listener to hear about it
a. Context events
b. Context attributes
c. Servlet requests
Why HttpSessionBindingListener
When the objects of the class want to know when they are added they
implement this interface.
This is useful e.g if customer data has changed and added to session so the
latest data has to be displayed and updated from the listener.
Entity beans implement this interface.
Remembering Listeners
Scope of Attributes :
1. Who can see it and how long does it live.
2. Attributes are not Parameters
Attribute Scope
4. enumeration getAttributeNames()
ii.
iii.
Ref : http://www.jguru.com/faq/view.jsp?EID=150