首页 新闻 搜索 专区 学院

Struts2 校验器,校验不了重复密码

0
悬赏园豆:20 [已解决问题] 解决于 2013-09-23 11:06
页面代码:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<s:fielderror fieldName="p1"/>
    <form method="post" action="r.action">
        <input name="p1" type="text"/>
        <input name="p2" type="text"/>
        <input type="submit"/> 
    </form>
</body>
</html>

 



Action类代码:

package qnhost.gw.action;

import com.opensymphony.xwork2.ActionSupport;

public class TestAction extends ActionSupport{

    @Override
    public String execute() throws Exception {
        return "OK";
    }

}

 



TestAction-r-validation.xml代码

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
        "-//Apache Struts//XWork Validator 1.0.2//EN"
        "http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd">
    
<validators>    
    
    <!-- 重复密码段校验-->
    <field name="p1">
        <field-validator type="fieldexpression">
            <param name="expression"> <![CDATA[(p1==p2)]]> 
            </param>
            <message>two password should be the same! </message>
        </field-validator>
    </field>
     
</validators>

 



现在的情况是不管怎么输入,较验都是成功的!是哪里错了?


补充下,如果把(p1==p2)换成p1.equals(p2),则不管怎么输入,校验都是不通过的。
喜欢凯的蓝的主页 喜欢凯的蓝 | 初学一级 | 园豆:186
提问于:2013-09-02 21:30
< >
分享
最佳答案
0
喜欢凯的蓝 | 初学一级 |园豆:186 | 2013-09-07 21:13
其他回答(2)
0
收获园豆:20
Beyond-bit | 园豆:2820 (老鸟四级) | 2013-09-02 22:55
0

(1)非字段校验:

    <validator type="fieldexpression">

        <param name="fieldName">myField</param>

        <param name="expression"><![CDATA[#myCreditLimit > #myGirfriendCreditLimit]]></param>

        <message>My credit limit should be MORE than my girlfriend</message>

    </validator>

(2)字段校验:

    <field name="myField">

        <field-validator type="fieldexpression">

            <param name="expression"><![CDATA[#myCreditLimit > #myGirfriendCreditLimit]]></param>

            <message>My credit limit should be MORE than my girlfriend</message>

        </field-validator>

    </field>

friends0615 | 园豆:202 (菜鸟二级) | 2016-03-28 18:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册