[JavaWeb: servlet+mysql+jsp] Access database data and realize page jump (complete code)

premise

My MySQL version is

My SQLyog version is

Before this case, I have completed the configuration of Java connection to the database. The specific content has been discussed in the previous article and will not be repeated here.

My directory is as follows (the following are the .java, .jsp and .xml files created):

Step preview

Create database tables:
emp table: stores employee information
user table: stores user account and password information

Writing order:
1. TestDb: Test whether the database connection is successful
2. Users.java: Entity class of user account and password information
3. Emp.java: Employee information entity class
4. login.jsp: Typesetting of input boxes and buttons
5. success .jsp: prompts that the login is successful
6. UsersDao.java: stores the method of realizing account and password login
7. EmpDao.java: stores the method of querying the entire employee table
9. EmpDao.java: stores the method of querying the entire employee table
8. UsersLoginServlet.java : Jump after the user successfully logs in
9. EmpQueryAllServlet.java queries the entire employee table
10. web.xml: Put login.jsp on the first page to appear
 

1. Create User and Emp entity classes

In the src path, create a package named: com.qingruan.bean (com is followed by the company name) to store the User entity class and Emp entity class.

The User class contains attributes: id, username, password, sex, birthday, address;

The Emp class contains attributes: empno, ename, job, sal, comm, hiredate, deptId;

Users.java

package com.qingruan.bean;

public class Users {

    private Integer id;

    private String username;

    private String password;

    private String sex;

    private String birthday;

    private String address;


    public Users() {
        // TODO Auto-generated constructor stub
    }


    public Users(Integer id, String username, String password, String sex, String birthday, String address) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.sex = sex;
        this.birthday = birthday;
        this.address = address;
    }


    @Override
    public String toString() {
        return "Users [id=" + id + ", username=" + username + ", password=" + password + ", sex=" + sex + ", birthday="
                + birthday + ", address=" + address + "]";
    }


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}

Emp.java

package com.qingruan.bean;

public class Emp {

    private Integer empno;

    private String ename;

    private String job ;

    private double sal;

    private double comm;

    private String hiredate;

    private Integer deptId;

    public Emp() {
        // TODO Auto-generated constructor stub
    }

    public Emp(Integer empno, String ename, String job, double sal, double comm, String hiredate, Integer deptId) {
        super();
        this.empno = empno;
        this.ename = ename;
        this.job = job;
        this.sal = sal;
        this.comm = comm;
        this.hiredate = hiredate;
        this.deptId = deptId;
    }


    @Override
    p

Guess you like

Origin blog.csdn.net/xjj1128/article/details/127440081
Recommended