strtus2中的AJAX验证
高手看哈啊我DWR用的1.1.4 struts2用的是2.0.12
实现注册验证:
regist.jsp为:
<%@ page language="java" contentType="text/html; charset=GBK"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>请输入您的注册信息</title>
<s:head theme="ajax"/>
</head>
<body>
<H1>请输入您的注册信息</H1>
<s:form action="regist" theme="ajax" validate="true">
<s:textfield name="name" label="作者名"/><br>
<s:textfield name="pass" label="密码"/>
<s:textfield name="age" label="年龄"/>
<s:textfield name="birth" label="生日"/>
<s:submit value="注册"/>
</s:form>
</body>
dwr.xml配制为:
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
<allow>
<create creator="new" javascript="validator">
<param name="class" value="org.apache.struts2.validators.DWRValidator"/>
</create>
<convert converter="bean" match="com.opensymphony.xwork2.ValidationAwareSupport"/>
</allow>
<signatures>
<![CDATA[
import java.util.Map;
import org.apache.struts2.validators.DWRValidator;
DWRValidator.doPost(String, String, Map<String, String>);
]]>
</signatures>
</dwr>
web.xml的配制为:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="2.4" xmlns="http://java.
xmlns:xsi="http://www. xsi:schemaLocation="http://java. http://java.
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>dwr</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<jsp-config>
<taglib>
<taglib-uri>http://java.
<taglib-location>/WEB-INF/tld/c.tld</taglib-location>
</taglib>
</jsp-config>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
validator包的RegistAction为:
package validate;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Pattern;
import com.opensymphony.xwork2.ActionSupport;
public class RegistAction extends ActionSupport{
private String name;
private String pass;
private int age;
private Date birth;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public String execute() throws Exception{
return "show";
}
}
RegistAction-validation.xml为:
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.
<validators>
<field name="name">
<field-validator type="requiredstring" short-circuit="true">
<param name="trim">true</param>
<message>${getText("name.required")}</message>
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[(\w{4,25})]]></param>
<message>${getText("name.regex")}</message>
</field-validator>
</field>
<field name="pass">
<field-validator type="requiredstring" short-circuit="true">
<param name="trim">true</param>
<message>${getText("pass.required")}</message>
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[(\w{4,25})]]></param>
<message>${getText("pass.regex")}</message>
</field-validator>
</field>
<field name="age">
<field-validator type="int">
<param name="min">1</param>
<param name="max">150</param>
<message>${getText("age.range")}</message>
</field-validator>
</field>
<field name="birth">
<field-validator type="date">
<param name="min">1900-01-01</param>
<param name="max">2008-01-01</param>
<message>${getText("birth.range")}</message>
</field-validator>
</field>
</validators>
国际化也没错,,
为什么验证的时候没有随焦点的改变而验证,,而是要点注册才能验证,,也就是没有实现AJAX,,,求大家帮我看哈这是怎么回事啊,,,,,,,,