2 qq 24166417 qq_24166417 于 2014.12.18 11:55 提问

tomcat总是报下面这个错误,该怎么解决啊。。希望各位大神能够帮我解决。。感谢

java.lang.NoClassDefFoundError: Filter
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2957)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:529)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:511)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:139)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4809)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5485)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
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:619)
Caused by: java.lang.ClassNotFoundException: Filter
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 26 more
2014-12-18 11:39:10 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter HibernateFilter
java.lang.NoClassDefFoundError: Filter
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2957)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:529)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:511)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:139)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4809)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5485)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
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:619)
Caused by: java.lang.ClassNotFoundException: Filter
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 26 more
2014-12-18 11:39:10 org.apache.catalina.core.StandardContext startInternal
严重: Error filterStart
2014-12-18 11:39:10 org.apache.catalina.core.StandardContext startInternal
严重: Context [/MedicineManager] startup failed due to previous errors

6个回答

qq_24166417
qq_24166417   2014.12.18 17:06

配置文件中是这样写的:

<filter>
    <filter-name>CharacterEncodingFilter</filter-name>
    <filter-class>com.lyq.util.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>
<!-- 自定义Hibernate过滤器 -->
<filter>
    <filter-name>HibernateFilter</filter-name>
    <filter-class>com.lyq.util.HibernateFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>HibernateFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
qq_24166417
qq_24166417 我现在出现了这个错误 了。。java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
接近 3 年之前 回复
qq_24166417
qq_24166417 我换了一个mySQL驱动包,没有报这个错误了。 谢谢你了
接近 3 年之前 回复
xmt1139057136
xmt1139057136 你的jar包肯定不全,你看看到底少了哪些jar包文件。我下班了,明天再给你看看,你先自己检查检查。多百度搜索搜索!!
接近 3 年之前 回复
xmt1139057136
xmt1139057136 http://bbs.csdn.net/topics/370193538
接近 3 年之前 回复
xmt1139057136
xmt1139057136 http://bbs.csdn.net/topics/340104873
接近 3 年之前 回复
qq_24166417
qq_24166417   2014.12.18 12:04

下面是Hibernate过滤器

public class HibernateFilter implements Filter{
// ThreadLocal对象
private static ThreadLocal threadLocal = new ThreadLocal();
// SessionFactory对象
private static SessionFactory factory = null;
public void destroy() {
if(!factory.isClosed()){
factory.close();
}
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
try {
chain.doFilter(request, response);
} finally{
Session session = (Session)threadLocal.get();
if(session != null){
if(session.isOpen()){
session.close();
}
threadLocal.remove();
}
}
}
public void init(FilterConfig arg0) throws ServletException {
//初始化SessionFactory
try {
Configuration cfg = new Configuration().configure();
factory = cfg.buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 获取Session
* @return Session
*/
public static Session getSession() {
Session session = (Session)threadLocal.get();
if (session == null) {
session = factory.openSession();
threadLocal.set(session);
}
return session;
}
}

u013147600
u013147600   2014.12.18 14:32

不知道是不是 doFilter()中异常处理少了catch导致过滤器启动失败

u013147600
u013147600 回复qq_24166417: 那你断点调试下 看看具体是哪里的错 这样看我是看不错哪里有错
接近 3 年之前 回复
qq_24166417
qq_24166417 加了catch,还是一样的错误
接近 3 年之前 回复
qq_24166417
qq_24166417   2014.12.18 16:25

错误是这样的:

严重: Exception starting filter CharacterEncodingFilter
java.lang.NoClassDefFoundError: Filter
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2957)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:529)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:511)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:139)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4809)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5485)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
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:619)
Caused by: java.lang.ClassNotFoundException: Filter
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 26 more
2014-12-18 16:19:33 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter HibernateFilter
java.lang.NoClassDefFoundError: Filter
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2957)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:529)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:511)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:139)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4809)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5485)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
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:619)
Caused by: java.lang.ClassNotFoundException: Filter
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 26 more
2014-12-18 16:19:33 org.apache.catalina.core.StandardContext startInternal
严重: Error filterStart
2014-12-18 16:19:33 org.apache.catalina.core.StandardContext startInternal
严重: Context [/MedicineManager] startup failed due to previous errors

qq_24166417
qq_24166417   2014.12.18 16:32

CharacterEncodingFilter字节编码过滤器如下:

public class CharacterEncodingFilter implements Filter{

protected String encoding = null;
protected FilterConfig filterConfig = null;

public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    this.encoding = filterConfig.getInitParameter("encoding");
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    if (encoding != null) {
        request.setCharacterEncoding(encoding);
        response.setContentType("text/html; charset="+encoding);
    }
    chain.doFilter(request, response);
}

public void destroy() {
    this.encoding = null;
    this.filterConfig = null;
}

}

xmt1139057136
xmt1139057136   Rxr 2014.12.18 16:43

这个问题是说,找不到CharacterEncodingFilter这个类。字符编码工具类CharacterEncodingFilter.java。他是spring架包中的一个类,你看看你是不是少了这个jar包。
或者与servlet-api.jar冲突!!!!

        <filter-name>encoding</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


qq_24166417
qq_24166417 回复xmt1139057136: 我贴了字节编码过滤器和自定义的Hibernate过滤器
接近 3 年之前 回复
xmt1139057136
xmt1139057136 回复qq_24166417: 能把你的web.xml贴出来,看一下吗
接近 3 年之前 回复
xmt1139057136
xmt1139057136 回复qq_24166417: 你搜索一下,看看你的项目中是否存在org.springframework.web.filter.CharacterEncodingFilter这个类
接近 3 年之前 回复
qq_24166417
qq_24166417 我这个项目没有用到Spring。。用的是Struts+Hibernate+MySQL
接近 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!