JSP Tutorial

Properties of Java Beans

Properties or characteristics of Java Beans:

Every JavaBeans class contains simple property, boolean property and indexed properties.

  • A simple property is one in which a method takes and returns elementary or single value (set of set and get methods are known as simple properties of a JavaBeans class.)
  • A boolean property is one in which a method takes or return boolean value.
  • An indexed property is one in which a method takes or return array of values.

Develop a JavaBeans class which will check whether the username and password correct or not?

Answer:

Test.java:

package abc;

public class Test {

    String uname;
    String pwd;

    public void setUname(String uname) {
        this.uname = uname;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getUname() {
        return (uname);
    }

    public String getPwd() {
        return (pwd);
    }

    public boolean validate() {
        if (uname.equals("kalpana") && pwd.equals("test")) {
            return (true);
        } else {
            return (false);
        }
    }
};

Note:It is highly recommended to use a JSP page with scriptless.