【发布时间】:2020-08-07 02:29:57
【问题描述】:
问题 当我运行我的项目并尝试运行时
ERROR Dispatcher Dispatcher initialization failed
Unable to load configuration. - bean - jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%208.5/wtpwebapps/Struts2Test/WEB-INF/lib/struts2-gxp-plugin-2.5.22.jar!/struts-plugin.xml:27:162
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:69)
and more...
http://localhost:8081/Struts2Test/testAction
它不起作用。它显示 HTTP 状态 404(在我的浏览器上)
Eclipse 控制台
Eclipse 控制台没有错误
/Struts2Test/src/struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="test" extends="struts-default">
<action name="testAction" class="test.Action.TestAction" method="execute">
<result name="success">
/success.jsp
</result>
<result name="error">
/error.jsp
</result>
</action>
</package>
</struts>
TestAction.java
package test.Action;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction extends ActionSupport
{
public String execute()
{
return "success";
}
}
/Struts2Test/WebContent/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Struts2Test</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
【问题讨论】:
-
你真的在使用 GXP插件吗?
-
我不知道。如何检查我是否使用 GXP 插件?@Dave Newton
-
...如果您不知道,那么您就没有使用它。不要随意将 S2 库放入您的应用程序中;只使用你需要的东西。我建议使用 Maven。
-
我错误地将我的 struts.xml 文件放入了包中。它在项目结构中不可见。昨晚我经历了很多类似问题的stackoverflow帖子。我意识到 maven 项目的 struts.xml 应该在类 WEB-INF/classes 中,而对于动态 Web 项目,它应该在 src 文件夹中。虽然我仍然不明白为什么它应该在类路径上?@Dave Newton
-
因为它是从类路径加载的。
标签: java jsp struts2 action-mapping