struts2.2.1写了个小例子,不验证时正常运行,使用validation.xml验证出错,不知道怎么回事,请教大家支招:
TestAction.java
[code="java"]
package test;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction extends ActionSupport {
private String name = null;
private int age = 0;
public String doInit(){
return SUCCESS;
}
public String doSave(){
System.out.println(name);
System.out.println(age);
return SUCCESS;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
[/code]
test.jsp
[code="java"]
<%@ page contentType="text/html;charset=gb2312" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
test
function doSave(){ document.forms[0].action="save.do"; document.forms[0].target = "_self"; document.forms[0].submit(); }
姓名:
年龄:
struts.xml
[code="java"]
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<!-- Include webwork default (from the Struts JAR). -->
<!-- Configuration for the default package. -->
<package name="default" extends="struts-default">
<!-- Default interceptor stack. -->
<action name="index" class="test.TestAction" method="init">
<result name="input">/jsp/test.jsp</result>
<result name="success">/jsp/test.jsp</result>
</action>
<action name="save" class="test.TestAction" method="save">
<result name="input">/jsp/test.jsp</result>
<result name="success">/jsp/test.jsp</result>
</action>
</package>
[/code]
保存时出现如下错误:
java.lang.NoSuchMethodException: test.TestAction.save()
java.lang.Class.getMethod(Class.java:1605)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:161)
使用jar包如下:
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
freemarker-2.3.16.jar
javassist-3.12.0.GA.jar
ognl-3.0.jar
struts2-core-2.2.1.jar
xwork-core-2.2.1.jar
工程参见附件。