📅  最后修改于: 2021-01-11 06:27:45             🧑  作者: Mango
int验证器检查给定的数字是否在指定范围内。可以在productId,employeeId等中使用。
为int验证器定义了3个参数。
Parameter | Description |
---|---|
fieldName | specifies the field name that is to be validated. It is required in Plain-Validator only. |
min | specifies the minimum value. It is ignored bydefault. |
max | specifies the maximum value. It is ignored bydefault. |
age
16
50
Age must be between ${min} and ${max}
16
50
Age must be between ${min} and ${max}
该jsp页面使用struts UI标记创建表单。它从用户那里接收名称,密码和电子邮件ID。
<%@ taglib uri="/struts-tags" prefix="s" %>
该操作类继承了ActionSupport类并覆盖了execute方法。
package com.javatpoint;
import com.opensymphony.xwork2.ActionSupport;
public class Register extends ActionSupport{
private int id;
private double price;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String execute(){
return "success";
}
}
在这里,我们使用捆绑的验证器来执行验证。
1
999
Id must be between ${min} to ${max}
该xml文件通过名称输入和拦截器jsonValidatorWorkflowStack定义了额外的结果。
index.jsp
welcome.jsp
它是显示用户信息的简单jsp文件。
<%@ taglib uri="/struts-tags" prefix="s" %>
Product Id:
Product price: