0
我已經正確定義了xml文件中的過濾器類,但是每次啓動servlet時,都會因爲無法啓動過濾器而引發錯誤。當我在日誌中看到,它指出java.lang.NoClassDefFoundError開始過濾器的異常 - Servlet
我的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>
我的卡塔利娜日誌錯誤
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)。但我不知道爲什麼。我只是有一個疑問,我必須將其定義爲/ com/drona/action/LoginFilter在xml文件中?
不,web.xml配置採用類名稱。仔細檢查它是否真的在'WEB-INF/classes'中,並且沒有錯別字。 – 2014-09-03 03:05:26