Educational administration management system realizes 1-account login

Educational administration management system - account login implementation

Project structure

(1) Login interface

Enter the user name and password, select the identity, and log in to the corresponding student interface and teacher interface.

(2) System student interface

Display the student's name and student number on the interface.
Display basic information of students.
Query course information: enter course number and teacher number. Show course information. Course number and teacher number can be blank.
Course selection interface: enter course number and teacher number. Take the appropriate course. To display an error message (not as good as a course number error or a teacher number error).
Drop out interface: displays the class list of the student, and the student can select the corresponding content for drop out submission.
Display student's report form: select the corresponding semester to display the final report form.
Course schedule: displays the semester and the contents of the course schedule.
Exit: exit the current account. Go back to the login screen.

(3) System teacher interface

Display the teacher's name and student number on the interface
Display basic information of Teachers
Check the student grades in the class. Select the semester, jump out of the course schedule, click the course number, and a modal box will pop up to display the students' grades in the class.
Overall distribution of student performance. Select semester, the course drop-down menu will automatically change to the course of the current semester, and select course. According to the course and semester, we can see the overall distribution of students' scores.
Student performance login. Show the course of the current semester, show the student table according to the semester selected by the teacher, and finally submit the scores.
Course information. Select the semester and course and display the course table with the course details. Click on the course number, there is a student table, displaying the details of students.

Different function realization

1. Login interface

Front end: bootstrap+jquery

Submit using the form. Form design:

<!--Enter the user name and password in the input box, and select the identity.-->
<!--required Indicates that it must be entered.-->
<div class="container"><br>
        <form id="login_form" name="login_form" onsubmit="return false" action="##" method="get">
            <div class="form-group">
                <lable for="username">User:</lable>
                <input type="text" class="form-control" id="username" placeholder="enter one user name" name="id" required>
            <div class="form-group">
                <lable for="password">Password:</lable>
                <input type="password" class="form-control" id="password" placeholder="Please input a password" name="pwd" required>

            <div class="radio">
                <lable><input type="radio" name="identity" value="student" required>Student</lable>
                <lable><input type="radio" name="identity" value="teacher" required>Teacher</lable>
            <input id="login" type="button" class="btn btn-primary" value="Land" onclick="login_check()">
            <p id="success"></p>

Data is delivered via ajax:

function login_check() {//Land
            var check_res;
            var is_send;
            //Data returned in the form
            var id = $("input[name=id]").val();
            var pwd = $("input[name=pwd]").val();
            var identity = $("input[name=identity]:checked").val();
                type: "get",
                //Data type of server response
                dataType: "text",
                url: "http://localhost:8080/login",
                //Send json type data
                data: {
                    "id": id,//User name
                    "pwd": pwd,//Password
                    "identity": identity
                //Send to server default data type
                //Allow cross domain requests
                // crossDomain:true,
                //Specifies that string data is returned from the server
                // contentType: 'application/json',
                success: function (result) {
                    check_res = result;
                    is_send = true;
                    if (check_res == "true_student") {
                        $("#Success). Text ("login succeeded");
                        //Jump to student interface
                    } else if(check_res=="true_teacher"){
                        $("#Success). Text ("login succeeded");
                        //Jump to teacher interface
                    } else if(check_res=="false"){
                        console.log("logging error!");
                        $("#success").text(" wrong user name or password! "";
                    } else{
                        console.log("haven't receive data");
                error: function (XMLHttpRequest,textStatus) {
                    $("#success").text(" error ");
                    alert(XMLHttpRequest.readyState);//Debug status code
                    is_send = false;

Backend: servelt

1. Students:
public class student {
    String id;
    String name;
    String sex;
    String college;
    String hometown;
    String phone_number;
    String birthday;
    public student(String id,String name,String sex,String college,
                   String hometown,String phone_number,String birthday){ = id; = name; = sex; = college;
        this.hometown = hometown;
        this.phone_number = phone_number;
        this.birthday = birthday;
    public void setId(String id){ = id;
    public String getId(){
        return id;
    public void setName(String name){;
    public String getName(){
        return name;
    public void setSex(String sex){;
    public String getSex(){
        return sex;
    public void setCollege(String college){;
    public String getCollege(){
        return college;
    public void setHometown(String hometown){
    public String getHometown(){
        return hometown;
    public void setPhone_number(String phone_number){
    public String getPhone_number(){
        return phone_number;
    public void setBirthday(String birthday){
        this.birthday = birthday;
    public String getBirthday(){
        return birthday;
2. Teachers:
public class teacher {
    String id;//Job number
    String name;//Full name
    String gender;//Gender
    String birthday;//Date of birth
    String level;//level
    double wages;//wages
    String department;//Faculty and department
    public void setId(String id){;
    public String getId(){
        return id;
    public void setName(String name){;
    public String getName(){
        return name;
    public void setGender(String gender){
    public String getGender(){
        return gender;
    public void setBirthday(String birthday){
        this.birthday = birthday;
    public String getBirthday(){
        return birthday;
    public void setLevel(String level){
    public String getLevel(){
        return level;
    public void setWages(double wages){
    public double getWages(){
        return wages;
    public void setDepartment(String department){
    public String getDepartment(){
        return department;

3. Login: servlet class
private static final long serialVersionUID = 1L;
    static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://localhost:3306/school";
    static final String USER = "root";
    static final String PASS = "ammy990427";
    JsonArray json = null;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Connection conn = null;
        Statement stmt = null;
        System.out.println("Login interface: get");
        //Get form information
        String identity = request.getParameter("identity");
        String userName = request.getParameter("id");
        String password = request.getParameter("pwd");
        System.out.printf("%s %s %s\n",identity,userName,password);
            //Database connection
            student s = new student("null","null","null","null","null",
            teacher t = new teacher();
            conn = DriverManager.getConnection(DB_URL,USER,PASS);
            stmt = conn.createStatement();
            String sql;
            PrintWriter out = response.getWriter();
                System.out.println("Current login status: Student");
                sql="select stid,passwd from stuid where stid="+userName+";";
                System.out.println("Current login identity: Teacher");
                sql="select gh,passwd from teacherid where gh="+userName+";";
            ResultSet rs = stmt.executeQuery(sql);
            //Write the current record to the session
            HttpSession session = request.getSession();
            if(!{//If the user is not found in the database
                //Return string
            }else if(!rs.getString(2).equals(password)) {//If the passwords don't match
                //Return string
            }else{//If the user matches
//                response.setStatus(302);
                    //Return string
                    System.out.println((String) session.getAttribute("stu_id"));
                    System.out.println("student login");
                }else if(identity.equals("teacher")){
                    //Return string
                    System.out.println("teacher login");
        } catch (ClassNotFoundException | SQLException e) {
Code logic:

1. Get the form content, user name, password and identity
2. Connect to the database (jdbc), and verify the password according to the identity and user name:
There are two situations:
(1) User name does not exist
(2) Password error
(3) Verification passed
3. If it is the first two cases, the string false will be returned
4. By returning the string true and recording the student's information in the session.
5. The front end makes different responses according to the returned string information. If false, the user name or password error field will be displayed. If true, the student or teacher interface will be displayed.


1. session is used to store the login information, so add the following to the ajax in the front end:


2. There should be a filter in the servlet, which is often intercepted because of the CORS protocol (I don't understand why):

public class Filter implements javax.servlet.Filter {
    public void destroy() {

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
//        chain.doFilter(req, resp);
        HttpServletResponse response = (HttpServletResponse) resp;
        HttpServletRequest request = (HttpServletRequest) req;
        String origin = request.getHeader("Origin");
        String[] allowDomain = {"http://localhost:63343","http://localhost:63342"};
        Set<String> allowOrigin = new HashSet<String>(Arrays.asList(allowDomain));
            response.setHeader("Access-Control-Allow-Origin", origin);
            response.setHeader("Access-Control-Allow-Credentials", "true");
            response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
//            response.setHeader("Access-Control-Max-Age", "3600");
//            response.setHeader("Access-Control-Allow-Headers", "x-requested-with,Authorization");
        System.out.println("filter implement");

    public void init(FilterConfig config) throws ServletException {



In allowDomain is the allowed http header (I don't know what to say). In the URL pattern in the deployment, the scope is all servlet s, which is "/ *".
3. The deployment in web.xml will not be described in detail.

Published 1 original article, praised 0, visited 8
Private letter follow

Tags: Session JDBC SQL JSON

Posted on Sat, 08 Feb 2020 01:08:37 -0800 by joix