Friday, 1 July 2016

What are different main elements of deployment descriptor ?


Servlet

servlet 
  • servlet-name 
    • Unique name of servlet for the Web application
  • servlet-class 
    • Fully qualified class name of the servlet
  • init-param 
    • Key / value pair as an initialization param of the servlet
servlet-mapping (servlet-name , url-pattern)
  • Mapping between a servlet and a URL pattern 
  • servlet-name 
    • Unique name of servlet 
  • url-pattern 
    • URL pattern of the mapping
Example
<servlet>
    <servlet-name>
MyFrontControllerServlet</servlet-name>
    <display-name>
MyFrontControllerservlet</display-name>
    <description>The main servlet</description>
    <servlet-class>
         com.demo.
MyFrontControllerServlet 
    </servlet-class>
    <init-param>
         <param-name>xml</param-name>
         <param-value>/WEB-INF/conf/myapp.xml</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>

</servlet>
 
<servlet-mapping>
    <servlet-name>
MyFrontControllerServlet</servlet-name>
    <url-pattern>/myapp/*</url-pattern>

</servlet-mapping>


Servlet context
Servlet Context init parameters
context-param (param-name, param-value, description) 

  • Key / value pair as an initialization param associated with the web application 
  • Each parameter name must be unique in the web application 
  • These can be accessed in servlet by : 
    • ServletContext.getInitParameter
    • ServletContext.getInitParameterNames
Example
<web-app>
  <context-param>
     <param-name>Webmaster</param-name>
     <param-value>webmaster@mycorp.com</param-value>
  </context-param>
</web-app>

 


Filter
filter
  • filter-name 
    • Unique name of filter for the Web application
  • filter-class 
    • Fully qualified class name of the filter
  • init-param 
    • Key / value pair as an initialization param of the filter

filter-mapping (servlet-name , url-pattern)
  • Mapping between a filter and resource (servlet / JSP)
  • filter-name 
    • Unique name of filter
  • servlet-name
    • Name of servlet to be wrapped by the filter
Example
<filter>
  <filter-name>HibernateSessionFilter</filter-name>
  <description>

      Close Hibernate session after each request
  </description>
  <filter-class>
      com.demo.HibernateSessionFilter
  </filter-class>

</filter>

<filter-mapping>
   <filter-name>HibernateSessionFilter</filter-name>
   <servlet-name>MyFrontControllerServlet</servlet-name>

</filter-mapping>


Listeners
ServletContextListener

  • Its implementations receives notifications about changes to the servlet context of the web application.
  • contextInitialized(ServletContextEvent sce)
    • called when web application is ready to process requests
  • contextDestroyed(ServletContextEvent sce)
    • called when servlet context is about to be shut down

ServletContextAttributeListener
  • Its implementation receives notifications of changes to the attribute list on the servlet context of a web application 
  • attributeAdded(ServletContextAttributeEvent scab)
    • called after a new attribute is added to the servlet context
  • attributeRemoved(ServletContextAttributeEvent scab)
    • called after an existing attribute has been removed from the servlet context
  • attributeReplaced(ServletContextAttributeEvent scab)
    • called after an attribute on the servlet context has been replaced

HttpSessionAttributeListener
  • It can be used to get notifications of changes to the attribute lists of sessions within this web application.
  • attributeAdded(ServletContextAttributeEvent scab)
    • called after a new attribute was added to the servlet context.
  • attributeRemoved(ServletContextAttributeEvent scab)
    • called after an existing attribute has been removed from the servlet context.
  • attributeReplaced(ServletContextAttributeEvent scab)
    • called when an attribute on the servlet context has been replaced

HttpSessionListener
  • notifies for the changes to the list of active sessions in a web application.
  • sessionCreated(HttpSessionEvent se)
    • called when a session is created
  • sessionDestroyed(HttpSessionEvent se)
    • called when a session is invalidated

HttpSessionActivationListener
  • Objects that are bound to a session may listen to container events notifying them that sessions will be passivated and that session will be activated.
  • It can be used when a container that migrates session between VMs or persists sessions and it is required to notify all attributes bound to sessions.

HttpSessionBindingListener 
  • Object is notified when it is bound to or unbound from a session.
Example
<listener>
   <listener-class>
        com.francetelecom.csrtool.gui.init.StartupListener
   </listener-class>

</listener>


display-name
  • Display name of web application
Example
<display-name>My App</display-name>


Icon
  • small-icon
  • large-icon
Example
<icon>
    <small-icon>/resource/icons/
demoSmall.gif</small-icon>
    <large-icon>/resource/icons/demoBig.gif</large-icon>

</icon>




welcome-file-list
  • Default file or URL pattern to redirect at entering context root
Example
<welcome-file-list>
   <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

No comments:

Post a Comment

Note: only a member of this blog may post a comment.