What are the possible causes for ServletContextListener to not be called
I am studying a Java Server, and I came across a problem with ServletContextListener. I see that it is not called, so when I do and getAttribute it always return null, because that attribute is not set in the class implementing ServletContextListener. I have cheked the code in web.xml and I see that it is delcared there too.
What else could the problem be ? The code its very long so I will post a small part of it.package common;
// import stuff
public class ServerContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent event) {
ServletContext context = event.getServletContext();
context.setAttribute(Const.ATTR_LICENSES, licenses);
// code here
}
}
@Override
public void contextDestroyed(ServletContextEvent event) {
// code here
}
// other file
Licenses licenses = (Licenses) context.getAttribute(Const.ATTR_LICENSES); // this returns null
And this is a part from web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<display-name>mymob</display-name>
<context-param>
<param-name>jobQueueName<开发者_开发技巧;/param-name>
<param-value>mobileJobQueue</param-value>
</context-param>
<listener>
<listener-class>common.ServerContextListener</listener-class>
</listener>
//other parameters
精彩评论