Pair Programming achieve JavaWeb

Tips:

https://shihuan.site/OnlinePaper/jsp/

This is the final realization of all the features of the test URL, we welcome the landing test, but due to the limited number of registration messages, so a test account for testing

Account: Zhiwang

Password: 123456Aa

 Interface display:

 

 

 

Environmental Choice: As the semester elective javaee course, while many of the courses curriculum design need to be website design, while our team selected projects also need to use the Web project, so I chose java as a development environment for this pair programming, project development, but also considered the effect of test javaee learning

 

Front end: HTML + CSS + BOOTSTRAP

Mainly using bootstrap front-end design

Backend: Servlet + Tomcat + JavaBean + JDBC + Ajax

The feeling is that this time the project has been the practice course Javaee

 

 

I was mainly involved in landing the registration page and write the answer topic computing part of the design content

Landing part:

 

Use JDBC database, Ali Durid connection with the database connection pool, load the configuration file

 

Package JDBCUtils; 

Import com.alibaba.druid.pool.DruidDataSourceFactory; 

Import the javax.sql.DataSource;
 Import java.io.IOException;
 Import a java.io.InputStream;
 Import the java.sql.Connection;
 Import java.sql.SQLException;
 Import the java.util.Properties; 

/ ** 
 * tools use the JDBC connection pool Durid 
 * / 
public  class JDBCUtils { 

    Private  static the DataSource DS; 

    static { 

        the try {
             // 1. load profile 
            the Properties Pro = new new the Properties ();
            // Use ClassLoader load profile, obtaining input stream of bytes 
            the InputStream IS = JDBCUtils. Class .getClassLoader () the getResourceAsStream ( "druid.properties." ); 
            Pro.load (IS); 

            // 2. initialize the connection pool object 
            ds = DruidDataSourceFactory.createDataSource (Pro); 

        } the catch (IOException E) { 
            e.printStackTrace (); 
        } the catch (Exception E) { 
            e.printStackTrace (); 
        } 
    } 

    / ** 
     * Gets connection pool object 
     * / 
    public  static the DataSource getDataSource ( ) {
         return DS; 
    }


    /**
     * 获取连接Connection对象
     */
    public static Connection getConnection() throws SQLException {
        return  ds.getConnection();
    }
}
View Code

 

 

 

class contains the user account number and password and the corresponding get and set methods Method

 

package user;

public class User {
    private  int id;
    private  String username;
    private  String password;


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

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

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

    public int getId() {
        return id;
    }

    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}
User

 

 

 

    public User login(User loginUser){
        try {
            //1.编写sql
            String sql = "select * from user where username = ? and password = ?";
            //2.调用query方法
            User user = template.queryForObject(sql,new BeanPropertyRowMapper<User>(User.class),
                    loginUser.getUsername(), loginUser.getPassword());


            return user;
        } catch (DataAccessException e) {
            e.printStackTrace();//记录日志
            return null;
        }
    }
}
View Code

 

 

UserDao template utilized in classes and BeanPropertyRowMapper sql statement query, the query result and returns the package to the user class

 

 

 The landing page form to submit action is set to loginServlet, when the form is submitted method to get through request.GetParameter () account password and packaging to user, and then use userDao query, if the query is empty prove wrong, failed on landing.

Principle registration page are basically the same, except that sent the verification code. Here is Ali cloud SendSMS function, send SMS specific process is as follows:

Generating random codes native ---------> random codes using a jar aliyun packaged sent to the mobile phone function -----------> The codes stored the Session Request () in ----------> is the same alignment with the Session stored user input, should the same, the presentation of the current registration form, the package is registered user.

 

 

 

In which the front-end registration process account password is validated by the validation of JavaScript regular expression method, if the verification is successful then submit the form to enhance the sense of user experience and reduce the burden on the server.

 

 

 

 

The most difficult part of the project is how to feel drawn randomly generated subject the resulting answer. In this part of the code before the two people and improve re modifications and simplified to facilitate generating the calculation formula to calculate the answer. Finally, think of using

eval JavaScript function in () script will randomly draw the equation as a script execution to get the final answer, so we have to get in trigonometric equation value, division and square root expressions can be replaced by direct calculation, and in order to reduce difficulty of the work (in the case of very difficult because there are multiple brackets) we can only appear in a formula specified in brackets to simplify, to calculate the final answer.

 

 

We get some added features, such as the history of the subject, and so on

 

 

 

 

 

Experience and harvest:

  This project really was a "learning by doing" projects. Javaee learning relevant content based on the required function, although the technology is not needed now looks difficult, but in the process of learning and practice in or had some trouble. Pair programming process while also learning from each other, Network access, as the team behind the project to lay the foundation.

 

Guess you like

Origin www.cnblogs.com/wangzhiwang/p/11601045.html