启动过滤器的异常 - Servlet

时间:2014-09-03 03:04:12

标签: java xml servlets filter classnotfoundexception

我已经正确地定义了xml文件中的过滤器类,但每次启动servlet时都会抛出错误,因为无法启动过滤器。当我在日志中看到它时,它声明了java.lang.NoClassDefFoundError

我的xml代码:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 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">


<servlet>
    <servlet-name>userLogin</servlet-name>
    <servlet-class>UserAction</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>userLogin</servlet-name>
    <url-pattern>/userLogin</url-pattern>
</servlet-mapping>


<servlet>
    <servlet-name>userRegistration</servlet-name>
    <servlet-class>UserAction</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>userRegistration</servlet-name>
    <url-pattern>/userRegistration</url-pattern>
</servlet-mapping>


<servlet>
    <servlet-name>createUser</servlet-name>
    <servlet-class>UserAction</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>createUser</servlet-name>
    <url-pattern>/createUser</url-pattern>
</servlet-mapping>

<filter>
    <filter-name>loginFilter</filter-name>
    <filter-class>com.drona.action.LoginFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>loginFilter</filter-name>
    <url-pattern>/userLogin</url-pattern>
</filter-mapping>

</web-app>

我在catalina日志中的错误

03-Sep-2014 08:14:40.087 SEVERE [localhost-startStop-1]             org.apache.catalina.core.StandardContext.filterStart Exception starting filter loginFilter
java.lang.NoClassDefFoundError: com/drona/action/LoginFilter (wrong name: LoginFilter)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2479)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:880)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1294)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1177)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:550)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:531)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4603)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5210)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1071)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1722)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

03-Sep-2014 08:14:40.627 INFO [localhost-startStop-1]     org.apache.catalina.core.ApplicationContext.log ContextListener: contextInitialized()
03-Sep-2014 08:14:40.627 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log SessionListener: contextInitialized()

我的过滤器类LoginFilter与我在xml中定义的文件夹完全相同(WEB-INF / classes / com / drona / action / LoginFilter)。但我无法弄清楚为什么会这样。我只是怀疑我是否必须在xml文件中将其定义为/ com / drona / action / LoginFilter?

1 个答案:

答案 0 :(得分:0)

我想通知我是否将过滤器类放在classes文件夹而不是com.drona.action.filterclass中,并将过滤器类路径更改为LoginFilter,因此它将直接调用它..但这不是确切的解决方案,无论如何我会找到它或其他方式..必须检查所有可能的情况..