gpt4 book ai didi

java - 启动过滤器时出现异常 - Servlet

转载 作者:太空宇宙 更新时间:2023-11-04 14:35:32 27 4
gpt4 key购买 nike

我已经在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 ?

最佳答案

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

关于java - 启动过滤器时出现异常 - Servlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25635604/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com