严重:启动过滤器 struts2 java.lang.ClassNotFoundException 异常:org.apache.struts2.dispatcher.FilterDispatcher
我正在尝试在 struts 2 中制作一个小型登录应用程序。我的 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>StrutsPrj</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>Login.jsp</welcome-file>
</welcome-file-list>
</web-app>
Struts.xml:
<struts>
<package name="default" extends="struts-default" namespace="/">
<action name="login" method="execute"
class="struts2.LoginAction">
<result name="success">Welcome.jsp</result>
<result name="error">Login.jsp</result>
</action>
</package>
</struts>
login.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Screen - Struts 2</title>
</head>
<body>
<s:actionerror />
<s:form action="login.action" method="post">
<s:textfield name="username" value="UserName" size="20" />
<s:password name="password" value="Password" size="20" />
<s:submit method="execute" value="Login" align="center" />
</s:form>
</body>
</html>
Welcome.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome Screen - Struts 2</title>
</head>
<body>
<h2>Congrates, <s:property value="username" />...!</h2>
</body>
</html>
LoginAction.java:
package struts2;
public class LoginAction {
private String username;
private String password;
public String execute() {
if (this.username.equals("admin")
&& this.password.equals("admin123")) {
return "success";
} else {
return "error";
}
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
我已将这些库添加到我的项目中:
- commons-logging-1.0.4.jar
- struts2-core-2.1.8.1.jar
- ognl-2.6.11.jar
- xwork-2.1 .0.jar
- freemarker-2.3.9.jar
当我尝试在 Tomcat 6 上运行它时,出现以下错误:
Mar 10, 2011 1:17:59 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Java/jre6/bin/client;C:/Java/jre6/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Java\jdk1.5\bin\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Liquid Technologies\Liquid XML Studio 2009\XmlDataBinder7\Redist7\cpp\win32\bin;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\MySQL\MySQL Server 5.0\bin
Mar 10, 2011 1:17:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:newPrj' did not find a matching property.
Mar 10, 2011 1:17:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context/Loader} Setting property 'useSystemClassLoaderAsParent' to 'false' did not find a matching property.
Mar 10, 2011 1:17:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:StrutsPrj' did not find a matching property.
Mar 10, 2011 1:17:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context/Loader} Setting property 'useSystemClassLoaderAsParent' to 'false' did not find a matching property.
Mar 10, 2011 1:18:00 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Mar 10, 2011 1:18:00 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2037 ms
Mar 10, 2011 1:18:00 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Mar 10, 2011 1:18:00 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.32
Mar 10, 2011 1:18:01 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:269)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4071)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4725)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Mar 10, 2011 1:18:01 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Mar 10, 2011 1:18:01 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/StrutsPrj] startup failed due to previous errors
Mar 10, 2011 1:18:01 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Mar 10, 2011 1:18:01 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Mar 10, 2011 1:18:01 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/97 config=null
Mar 10, 2011 1:18:01 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1756 ms
I am trying to make a small login application in struts 2. My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>StrutsPrj</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>Login.jsp</welcome-file>
</welcome-file-list>
</web-app>
Struts.xml:
<struts>
<package name="default" extends="struts-default" namespace="/">
<action name="login" method="execute"
class="struts2.LoginAction">
<result name="success">Welcome.jsp</result>
<result name="error">Login.jsp</result>
</action>
</package>
</struts>
login.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Screen - Struts 2</title>
</head>
<body>
<s:actionerror />
<s:form action="login.action" method="post">
<s:textfield name="username" value="UserName" size="20" />
<s:password name="password" value="Password" size="20" />
<s:submit method="execute" value="Login" align="center" />
</s:form>
</body>
</html>
Welcome.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome Screen - Struts 2</title>
</head>
<body>
<h2>Congrates, <s:property value="username" />...!</h2>
</body>
</html>
LoginAction.java:
package struts2;
public class LoginAction {
private String username;
private String password;
public String execute() {
if (this.username.equals("admin")
&& this.password.equals("admin123")) {
return "success";
} else {
return "error";
}
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
And i have added these libraries to my project:
- commons-logging-1.0.4.jar
- struts2-core-2.1.8.1.jar
- ognl-2.6.11.jar
- xwork-2.1.0.jar
- freemarker-2.3.9.jar
When I try to run this on Tomcat 6 I got following error:
Mar 10, 2011 1:17:59 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Java/jre6/bin/client;C:/Java/jre6/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Java\jdk1.5\bin\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Liquid Technologies\Liquid XML Studio 2009\XmlDataBinder7\Redist7\cpp\win32\bin;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\MySQL\MySQL Server 5.0\bin
Mar 10, 2011 1:17:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:newPrj' did not find a matching property.
Mar 10, 2011 1:17:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context/Loader} Setting property 'useSystemClassLoaderAsParent' to 'false' did not find a matching property.
Mar 10, 2011 1:17:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:StrutsPrj' did not find a matching property.
Mar 10, 2011 1:17:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context/Loader} Setting property 'useSystemClassLoaderAsParent' to 'false' did not find a matching property.
Mar 10, 2011 1:18:00 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Mar 10, 2011 1:18:00 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2037 ms
Mar 10, 2011 1:18:00 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Mar 10, 2011 1:18:00 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.32
Mar 10, 2011 1:18:01 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:269)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4071)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4725)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Mar 10, 2011 1:18:01 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Mar 10, 2011 1:18:01 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/StrutsPrj] startup failed due to previous errors
Mar 10, 2011 1:18:01 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Mar 10, 2011 1:18:01 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Mar 10, 2011 1:18:01 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/97 config=null
Mar 10, 2011 1:18:01 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1756 ms
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
如果您使用的是 Struts2 版本 2.5,则需要从 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 更改为 org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter。请参阅:
java.lang.ClassNotFoundException:org.apache。 web.xml 中的 struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
If you are using Struts2 version 2.5 you need to change from org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter to org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter. See:
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter in web.xml
我也遇到了这个错误,我检查了
web.xml
中的dtd
并将版本从 2.4 更改为 2.5 。I got this error too and I checked my
dtd
inweb.xml
and I changed the version from 2.4 to 2.5 .我建议进行 Maven 构建,依赖关系将由 Maven 解决。
这就是我必须放入 pom.xml 中的内容
I suggest doing a Maven build, the dependencies will be resolved by Maven.
This is what I had to put in pom.xml
看起来,您的类路径中缺少 commons-lang3-XXX.jar 文件。您可以通过将 jar 添加到 lib 文件夹来解决该问题。
It seems, commons-lang3-XXX.jar file is missing in your class path. You can resolve it by adding the jar to your lib folder.
关于错误:
问题:
以下组合似乎有问题
Eclipse - WTPPlugin - Struts2 - Maven3
调查结果:
我们假设当我们以“在服务器上运行”方式运行项目时,我们假设 eclipse 运行 maven,创建 WAR 文件并部署在服务器上。但它对我来说并不完美。我确实在maven创建WAR的目标文件夹中看到了WAR文件,并且WAR是完美的。但 eclipse 似乎运行着别的东西。
解决方案:
将所有必需的 JAR 文件放入 eclipse 项目的 WEB-INF/lib 中。
如果您使用版本控制,请确保忽略 lib 文件夹。
使用maven时如何找到所有需要的JAR?转到目标文件夹和 WAR 文件。打开它并转到 WEB-INF/lib。将所有这些 JAR 复制到 eclipse 项目的 WEB-INF/lib 中。
Regarding the error:
PROBLEM:
There seems to be a problem with the following combination
Eclipse - WTPPlugin - Struts2 - Maven3
FINDINGS:
We assume that when we run a project as "Run on server" we assume that eclipse runs maven, created WAR file and deploys on the server. But its not working perfectly for me. I do see the WAR file in the target folder where maven creates WAR, and the WAR is perfect. But eclipse seems to run something else.
SOLUTION:
Put all the required JAR files into eclipse project's WEB-INF/lib.
If you are using version control, make sure to ignore the lib folder.
How to find all the required JARs when you are using maven? Go to target folder and the WAR file. Burst it open and go to WEB-INF/lib. Copy all these JARS to eclipse project's WEB-INF/lib.
在启动strut2项目时遇到类似的问题。
我用的是最新的罐子。
Web.xml 的版本为 3.0。并且它的配置中不包含正确的调度程序。我添加了正确的调度程序过滤器,
即而不是
或者
它工作得很好。
Got similar problem while starting strut2 project.
I was using the latest jars.
Web.xml has version 3.0. And it does not contains the proper dispatcher in its configuration. I added the correct dispatcher filter i.e.
instead of
or
it worked greatly.
struts.action.excludePattern
常量设置现在给我带来了同样的麻烦。我没有得到任何解释,甚至没有像你一样的堆栈跟踪,只有纯粹的“错误 FilterStart”。我通过恢复到以前版本的代码来跟踪这一点并检查发生了什么变化。A
struts.action.excludePattern
constant setting caused to me the same trouble now. I didn't got any explanation, not even a stack trace as you, only a pure "error FilterStart". I tracked this by reverting to the previous versions of the code and checked, what changed.作为 Struts2 框架的新手,我最近遇到了相同(或非常相似)的错误。就我而言,我在 Action 类中使用注释,而不是在 struts.xml 文件中。
例如
,但是当我更改操作值以包含 *.action 扩展名(见下文)时,Struts 会抛出上面提到的“严重:异常启动过滤器 struts2”错误。
这个错误的原因并不明显,因为它没有立即显现出来。通过查看 Tomcat localhost..log 文件,我找到了错误的堆栈跟踪,并且能够解决该问题。
Being new to the Struts2 framework, I recently came across the same (or very similar) error. In my case I was using annotations within the Action class rather than the struts.xml file.
For example
However when I changed the action value to include the *.action extension (see below) Struts would throw the "SEVERE: Exception starting filter struts2" error noted above.
The cause of this error wasn't obvious as it didn't manifest itself immediately. Looking through the Tomcat localhost..log file I found the stacktrace for the error and was able to remedy the issue.
确保以下内容位于您的类路径上:
编辑:您是否关注了https://struts.apache.org/getting-started/how-to-create-a-struts2-web -application.html 来设置您的项目?
尝试:
Make sure the following are on your class path:
Edit: Have you followed https://struts.apache.org/getting-started/how-to-create-a-struts2-web-application.html to set up your project?
Try:
您需要再添加一个 jar commons-lang3-xx
,向下滚动到 apache 日志的末尾,您可以找到 ClassNotFoundException: org.apache.commons.lang3.StringUtils :
You need to add one more jar commons-lang3-x.x
scroll down to the end of apache logs you can find ClassNotFoundException: org.apache.commons.lang3.StringUtils :
我也有同样的问题。我是这样解决的:
首先,我删除了所有添加的库。然后我通过添加它们
项目->属性->部署程序集
。之前,我只是将它们复制到
WEB-INF/lib
文件夹中。这似乎并不总是有效。希望这有帮助。
I had the same problem. I solved it this way:
1st I deleted all my added libs. Then I added them via
Project->Properties->Deployment Assembly
.Before, I just copied them into the
WEB-INF/lib
folder. That doesn't seem to work all the time.hope this helps.
将 commons-lang3-jar 文件添加到 WEB-INF\lib 文件夹。
add commons-lang3- jar file to WEB-INF\lib folder.
只需将 commons-lang3XXXX.jar 添加到您的库中
just add commons-lang3XXXX.jar to your library