| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1413 人关注过本帖
标题:strtus2中的AJAX验证
只看楼主 加入收藏
fujinliang
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-3-30
结帖率:0
收藏
 问题点数:0 回复次数:2 
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,,,求大家帮我看哈这是怎么回事啊,,,,,,,,
搜索更多相关主题的帖子: 验证 AJAX 
2008-12-09 00:04
fujinliang
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-3-30
收藏
得分:0 
还有struts.xml为:
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.
<struts>
    <constant name="struts.custom.i18n.resources" value="messageResource"/>
    <constant name="struts.i18n.encoding" value="GBK"/>

    <package name="test" extends="struts-default">
    <action name="regist" class="validate.RegistAction">
    <result name="show">/show.jsp</result>
    <result name="input">/regist.jsp</result>
    </action>
    </package>
</struts>
2008-12-09 00:05
快速回复:strtus2中的AJAX验证
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021434 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved