日期:2014-05-18  浏览次数:20666 次

求助:web.xml的配置问题
我的web.xml文件内容
<?xml   version= "1.0 "   encoding= "ISO-8859-1 "?>
<web-app   xmlns= "http://java.sun.com/xml/ns/j2ee "
        xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance "
        xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "
        version= "2.4 ">

<servlet>
<servlet-name> ListenerTester </servlet-name>
<servlet-class> com.example.ListenerTester </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> ListenerTester </servlet-name>
<url-pattern> /ListenTest.do </url-pattern>
</servlet-mapping>
<context-param>
<param-name> breed </param-name>
<param-value> GreatDane </param-value>
</context-param>
<listener>
<listener-class> com.example.MyServletContextListener.class </listener-class>
</listener>

</web-app>
容器用的tomcat,如果我不加 <listener> 可以启动,但是一加 <listener> 就启动不了
这是我的监听器类的代码:
package   com.example;

import   javax.servlet.*;

public   class   MyServletContextListener   implements   ServletContextListener
{
public   void   contextInitialized(ServletContextEvent   event)
{
//ServletContext   sc=event.getServletContext();
//String   dogBreed=sc.getInitParameter( "breed ");
//sc.setAttribute( "dog ", "d ");
}

public   void   contextDestroyed(ServletContextEvent   event)
{}
}
我把所有注释掉,还是启动不了。还请高手指点阿

------解决方案--------------------
<listener>
<listener-class> com.example.MyServletContextListener.class </listener-class>
</listener>
里面的com.example.MyServletContextListener.class不需要加上class后缀吧
------解决方案--------------------
把 <listener> 元素放到 <servlet> 元素上试试