We have seen how to write servlets. How about writing a context listener for them? This will come in handy if you want to integrate with frameworks that use context listeners for initialization.
Following are the steps required to write a simple context listener:
Include the
servlet-context-listener
module in theatlassian-plugin.xml file
:<servlet-context-listener name="Test Servlet Listener" key="jtricksServletListener" class="com.jtricks.JTricksServletListener"> <description>Listener for Test Servlet</description> </servlet-context-listener>
Here, we have a unique module key and a class that is the servlet context listener's Java class.
Write the servlet context listener's class. The class must be
javax.servlet.ServletContextListener
:public class JTricksServletListener implements...