本文介绍了使用ServletContextlistener的ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当我尝试从 we.XML
获取上下文参数到 ServletContextListener
类时,我都会遇到异常,我是真的很难理解为什么它不起作用,
这是Apache Tomcat 7.0.11日志中的例外:
I get an exception whenever I try getting context parameter from we.XML
into a ServletContextListener
class, I am really having hard times understanding why It is not working,here's the exception in Apache Tomcat 7.0.11 log :
Oct 21, 2011 1:24:23 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class alaa.ServletContextListener
java.lang.ClassNotFoundException: alaa.ServletContextListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at
org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
at
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4618)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5184)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5179)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
这是我网络的一部分.xml:
Here's a part of my web.xml :
<context-param>
<param-name>catName</param-name>
<param-value>meshmesh</param-value>
</context-param>
<context-param>
<param-name>catBreed</param-name>
<param-value>egyptian</param-value>
</context-param>
<listener>
<listener-class>alaa.CatLisenter</listener-class>
</listener>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
这是我的ServletContextListener.java:
Here's my ServletContextListener.java:
package alaa;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class CatLisenter implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext sc = sce.getServletContext();
String name = sc.getInitParameter("catName");
String breed = sc.getInitParameter("catBreed");
Cat maCat = new Cat();
maCat.setName(name);
maCat.setBreed(breed);
sc.setAttribute("cat", maCat);
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
Here's Cat.java :
package alaa;
public class Cat {
private String name;
private String breed;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBreed() {
return breed;
}
public void setBreed(String breed) {
this.breed = breed;
}
}
many thanks
推荐答案
尝试清除tomcat工作目录并清理。之后,发布您的项目并再次运行。
Try to clear the tomcat work directory and clean. After that, publish your project and run again.
这篇关于使用ServletContextlistener的ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!