employeeform.java

来自「《精通JSP编程 》源代码(赵强那本) 很有用的源代码」· Java 代码 · 共 55 行

JAVA
55
字号
package edu.reumann;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionMapping;import org.apache.struts.action.ActionErrors;import org.apache.struts.action.ActionError; import javax.servlet.http.HttpServletRequest; public class EmployeeForm extends ActionForm  {    private String name;    private String age;    private String department;    public void setName(String name) {        this.name = name;    }    public void setAge(String age) {        this.age = age;    }    public void setDepartment(String department) {        this.department = department;    }    public String getName() {        return name;    }    public String getAge() {        return age;    }    public String getDepartment() {        return department;    }    public ActionErrors validate( ActionMapping mapping, HttpServletRequest request ) {        ActionErrors errors = new ActionErrors();                 if ( getName() == null || getName().length() < 1 ) {            errors.add("name",new ActionError("error.name.required"));        }        if ( getAge() == null || getAge().length() < 1 ) {            errors.add("age",new ActionError("error.age.required"));        }        else {            try {               Integer.parseInt( getAge() );            } catch( NumberFormatException ne ) {                errors.add("age",new ActionError("error.age.integer"));            }        }        return errors;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?