📅  最后修改于: 2021-01-11 06:24:51             🧑  作者: Mango
stringlength验证器指定字符串必须具有给定的长度。可以在用户名,密码等中使用。
默认情况下,它会修剪字符串,然后检查其长度是否为给定的长度。
为字符串长度验证器定义了4个参数。
Parameter | Description |
---|---|
fieldName | specifies the field name that is to be validated. It is required in Plain-Validator only. |
minLength | specifies the minimum length. It is ignored bydefault. |
maxLength | specifies the maximum length. It is ignored bydefault. |
trim | trims the field values. It is bydefault true means it is enabled bydefault. |
password
6
10
true
Password must be between 6 to 10 characters long
6
10
true
Password must be between 6 to 10 characters long
该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 String username,userpass;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserpass() {
return userpass;
}
public void setUserpass(String userpass) {
this.userpass = userpass;
}
public String execute(){
return "success";
}
}
在这里,我们使用捆绑的验证器来执行验证。
Name can't be blank
Password can't be blank
6
10
Password must be greater than or equal to 6 and less than or equal to 10
该xml文件通过名称输入和拦截器jsonValidatorWorkflowStack定义了额外的结果。
index.jsp
welcome.jsp
它是显示用户信息的简单jsp文件。
<%@ taglib uri="/struts-tags" prefix="s" %>
Welcome,