tomcat6.0.18,struts2.1.81,myeclipse6.0简单的一个例子居然就不能成功,纠结啊,已导入的jar包有7个,分别是:
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-logging-1.0.4.jar
freeer-2.3.15.jar
ognl-2.7.3.jar
struts2-core-2.1.8.1.jar
xwork-core-2.1.6.jar
我的web.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>HelloWord.jsp</welcome-file>
</welcome-file-list>
</web-app>
src下的struts.xml如下<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <package name="default" namespace="/" extends="struts-default">
<!-- 在这里添加Action定义 -->
<action name="HelloWord" class="example.HelloWord">
<result type="success">/HelloWord.jsp</result>
</action>
</package>
</struts>HelloWord.java 代码:
package example;import com.opensymphony.xwork2.ActionSupport;public class HelloWord extends ActionSupport {
public String execute() throws Exception {
setMessage("你好! struts2");
return SUCCESS;
} private String message; public String getMessage() {
return message;
} public void setMessage(String message) {
this.message = message;
}
}HelloWord.jsp代码:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %><html>
<head>
<title>Struts 2 示例</title>
</head>
<body>
<h2><s:property value="message"/></h2>
${message }
</body>
</html>
最后结果,连启动都启动不起来,错误信息如下:
严重: Dispatcher initialization failed
Unable to load configuration. - action - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:8:54Caused by: Error building results for action HelloWord in namespace / - action - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:8:54Caused by: There is no result type defined for type 'success' mapped with name 'success'. Did you mean 'success'? - result - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:9:27
2010-6-18 9:14:57 org.apache.catalina.core.StandardContext filterStart严重: Exception starting filter struts2
Unable to load configuration. - action - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:8:54Caused by: Unable to load configuration. - action - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:8:54Caused by: Error building results for action HelloWord in namespace / - action - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:8:54caused by: There is no result type defined for type 'success' mapped with name 'success'. Did you mean 'success'? - result - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:9:27严重: Dispatcher initialization failed
Unable to load configuration. - action - file:/D:/apache-tomcat-6.0.18/webapps/tutorial/WEB-INF/classes/struts.xml:9:57Caused by: Action class [tutorial.HelloWorld] not found - action - file:/D:/apache-tomcat-6.0.18/webapps/tutorial/WEB-INF/classes/struts.xml:9:572010-6-18 9:15:01 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
Unable to load configuration. - action - file:/D:/apache-tomcat-6.0.18/webapps/tutorial/WEB-INF/classes/struts.xml:9:57Caused by: Unable to load configuration. - action - file:/D:/apache-tomcat-6.0.18/webapps/tutorial/WEB-INF/classes/struts.xml:9:57Caused by: Action class [tutorial.HelloWorld] not found - action - file:/D:/apache-tomcat-6.0.18/webapps/tutorial/WEB-INF/classes/struts.xml:9:57本人刚工作,公司都是.NET的 没有学java 第一次学struts2 弄个小例子都运行不出来 那位高手帮解决下 我都要研究2天了 我感觉是配置文件错误 可是不知道错在那?
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-logging-1.0.4.jar
freeer-2.3.15.jar
ognl-2.7.3.jar
struts2-core-2.1.8.1.jar
xwork-core-2.1.6.jar
我的web.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>HelloWord.jsp</welcome-file>
</welcome-file-list>
</web-app>
src下的struts.xml如下<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <package name="default" namespace="/" extends="struts-default">
<!-- 在这里添加Action定义 -->
<action name="HelloWord" class="example.HelloWord">
<result type="success">/HelloWord.jsp</result>
</action>
</package>
</struts>HelloWord.java 代码:
package example;import com.opensymphony.xwork2.ActionSupport;public class HelloWord extends ActionSupport {
public String execute() throws Exception {
setMessage("你好! struts2");
return SUCCESS;
} private String message; public String getMessage() {
return message;
} public void setMessage(String message) {
this.message = message;
}
}HelloWord.jsp代码:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %><html>
<head>
<title>Struts 2 示例</title>
</head>
<body>
<h2><s:property value="message"/></h2>
${message }
</body>
</html>
最后结果,连启动都启动不起来,错误信息如下:
严重: Dispatcher initialization failed
Unable to load configuration. - action - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:8:54Caused by: Error building results for action HelloWord in namespace / - action - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:8:54Caused by: There is no result type defined for type 'success' mapped with name 'success'. Did you mean 'success'? - result - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:9:27
2010-6-18 9:14:57 org.apache.catalina.core.StandardContext filterStart严重: Exception starting filter struts2
Unable to load configuration. - action - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:8:54Caused by: Unable to load configuration. - action - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:8:54Caused by: Error building results for action HelloWord in namespace / - action - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:8:54caused by: There is no result type defined for type 'success' mapped with name 'success'. Did you mean 'success'? - result - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:9:27严重: Dispatcher initialization failed
Unable to load configuration. - action - file:/D:/apache-tomcat-6.0.18/webapps/tutorial/WEB-INF/classes/struts.xml:9:57Caused by: Action class [tutorial.HelloWorld] not found - action - file:/D:/apache-tomcat-6.0.18/webapps/tutorial/WEB-INF/classes/struts.xml:9:572010-6-18 9:15:01 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
Unable to load configuration. - action - file:/D:/apache-tomcat-6.0.18/webapps/tutorial/WEB-INF/classes/struts.xml:9:57Caused by: Unable to load configuration. - action - file:/D:/apache-tomcat-6.0.18/webapps/tutorial/WEB-INF/classes/struts.xml:9:57Caused by: Action class [tutorial.HelloWorld] not found - action - file:/D:/apache-tomcat-6.0.18/webapps/tutorial/WEB-INF/classes/struts.xml:9:57本人刚工作,公司都是.NET的 没有学java 第一次学struts2 弄个小例子都运行不出来 那位高手帮解决下 我都要研究2天了 我感觉是配置文件错误 可是不知道错在那?
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>web.xml一般都用FilterDispatcher吧?
<result type="success">/HelloWord.jsp</result>
</action>
红色的就是错误
去掉.或者改为name="success"
错误已经说得很清楚了, 是你的struts.xml的8行54列的错误
<action name="HelloWord" class="example.HelloWord">
<result type="success">/HelloWord.jsp</result>
是这个吗
name="HelloWord"不对,这里应该写方法名,比如HelloWord类中方法名为query(),
如果你在jsp的form的action属性中写的是helloWord_query,则name="helloWord_*"
<result type="success">这里不是type应该是name,是你在action里面return的字符串
----------
这位哥们 是哪位老师教你的说action的name是方法名的? 这样要method属性是吃白饭的么?
LZ初接触, 不要误导别人
Unable to load configuration. - action - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:8:54Caused by: Error building results for action HelloWord in namespace / - action - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:8:54Caused by: There is no result type defined for type 'success' mapped with name 'success'. Did you mean 'success'? - result - file:/D:/apache-tomcat-6.0.18/webapps/struts2hello/WEB-INF/classes/struts.xml:9:27
2010-6-18 9:14:57 org.apache.catalina.core.StandardContext filterStart明顯是<result type="success">/HelloWord.jsp</result>
配置錯誤,struts2 已經加載。只是加載struts.xml時出的錯誤。
改成<result name="success">/HelloWord.jsp</result>