Java 无法运行Struts 2 Hello World
问题 当我运行我的项目并尝试运行Java 无法运行Struts 2 Hello World,java,jsp,struts2,action-mapping,Java,Jsp,Struts2,Action Mapping,问题 当我运行我的项目并尝试运行 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.j
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状态
Eclipse控制台
Eclipse控制台上没有错误
/struts2测试/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>
/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>
你好,我是struts
在Eclipse企业版中创建动态web项目
Eclipse>文件>新建>动态Web项目
命名:HelloWorld
它应该在web内容文件夹>web-INF>web.xml中有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>HelloWorld</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>
/HelloWorld/WebContent/success.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1> Hello World</h1>
</body>
</html>
/HelloWorld/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>
注意:struts.xml文件应该位于动态web项目的src文件夹中。否则它将无法工作
<?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="com.test.TestAction" method="execute">
<result name="success">
/success.jsp
</result>
<result name="error">
/error.jsp
</result>
</action>
</package>
</struts>
您需要在Java构建路径中添加这些jar文件
选择项目>右键单击>属性>Java构建路径>添加外部Jar文件
现在,您需要在部署程序集中添加这些jar文件
选择您的项目>右键单击>属性>部署程序集>添加>单击Java构建路径>前面添加的jar文件将显示在那里。选择并确定
在服务器上运行您的项目
选择您的项目>运行方式>在服务器上运行
在浏览器上
我把端口号从8080改为8081。Tomcat的默认端口号是8080。因此,URL将被删除 Hello Worldin struts
在Eclipse企业版中创建动态web项目
Eclipse>文件>新建>动态Web项目
命名:HelloWorld
它应该在web内容文件夹>web-INF>web.xml中有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>HelloWorld</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>
/HelloWorld/WebContent/success.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1> Hello World</h1>
</body>
</html>
/HelloWorld/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>
注意:struts.xml文件应该位于动态web项目的src文件夹中。否则它将无法工作
<?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="com.test.TestAction" method="execute">
<result name="success">
/success.jsp
</result>
<result name="error">
/error.jsp
</result>
</action>
</package>
</struts>
您需要在Java构建路径中添加这些jar文件
选择项目>右键单击>属性>Java构建路径>添加外部Jar文件
现在,您需要在部署程序集中添加这些jar文件
选择您的项目>右键单击>属性>部署程序集>添加>单击Java构建路径>前面添加的jar文件将显示在那里。选择并确定
在服务器上运行您的项目
选择您的项目>运行方式>在服务器上运行
在浏览器上
我把端口号从8080改为8081。Tomcat的默认端口号是8080。因此,URL将被删除 你真的在使用GXP插件吗?我不知道。如何检查我是否使用GXP插件?@Dave Newton。。。如果你不知道,那你就不用它了。不要在应用程序中随机放置S2库;只使用你需要的。我建议使用Maven。我错误地将struts.xml文件放在包中。它在项目结构中不可见。昨晚我浏览了很多类似问题的stackoverflow帖子。我意识到maven项目的struts.xml应该在类WEB-INF/classes中,而动态WEB项目的struts.xml应该在src文件夹中。虽然我仍然不明白为什么它应该在类路径上?@Dave Newton,因为它是从类路径加载的。你真的在使用GXP插件吗?我不知道。如何检查我是否使用GXP插件?@Dave Newton。。。如果你不知道,那你就不用它了。不要在应用程序中随机放置S2库;只使用你需要的。我建议使用Maven。我错误地将struts.xml文件放在包中。它在项目结构中不可见。昨晚我浏览了很多类似问题的stackoverflow帖子。我意识到maven项目的struts.xml应该在类WEB-INF/classes中,而动态WEB项目的struts.xml应该在src文件夹中。尽管我仍然不明白为什么它应该在类路径上?@Dave newton,因为它是从类路径加载的。