/Login-application-with-Struts2

Login application with structs2 using MVC framework - NTU CZ3002

Primary LanguageJava

CZ3002 assignment 2: Login application with struts 2 and MySQL database

Files

  1. SQL script: db.sql
  2. WAR file: target -> login.war

How to run?

Before running, please make sure that the SQL server is running in the background.

  1. start server
    cd ..\mysql\bin
    mysqld --console

  2. run the code cd ..\login
    mvn jetty:run into terminal

Website: http://localhost:8080/login/view/login.jsp

Requirements

  1. Java jdk
  2. maven
  3. mysql
  4. mysql jdbc driver

Windows set up

Set up

  1. add JAVA_HOME into sys environment (Eg. C:\Progra~1\Java\jdk-12.0.1)
  2. add MAVEN_HOME into sys environment (Eg. C:\Progra~1\apache-maven-3.6.3)
  3. add path: %MAVEN_HOME%\bin; to environment

Set up MySQL database

  1. Download MySQL Community Server "ZIP ARCHIVE" from https://dev.mysql.com/downloads/mysql/:

    • Under "Other Downloads", download "Windows (x86, 64-bit), ZIP ARCHIVE (mysql-8.0.{xx}-winx64.zip)".
  2. UNZIP the downloaded file into your project directory "C:\MySQL". MySQL will be unzipped as "c:\MySQL\mysql-8.0.{xx}-winx64".

    • For EASE OF USE, we shall shorten and rename the directory to "c:\MySQl\mysql". Take note and remember your MySQL installed directory!!!
  3. (NEW since MySQL 5.7.7) Initialize the database: Start a CMD (as administrator) ("Search" button ⇒ Enter "cmd" ⇒ Right-Click on "Command Prompt" ⇒ Run as Administrator) and issue these commands:

    • Change directory to the MySQL's binary directory
    • Eg. Suppose that your MySQL is installed in "c:\MySQL\mysql" cd \MySQL\mysql\bin
  4. Initialize the database. Create a root user with random password & show the messages on console. mysqld --initialize --console

    • A temporary password is generated for root@localhost: xxxxxxxx
    • During the installation, a superuser called root is created with a temporary password, as shown above. TAKE NOTE of the PASSWORD, COPY and SAVE it somewhere, and also TAKE A PICTURE!!!
  5. If you make a mistake or forgot your password, DELETE the entire MySQL directory "C:\MySQL\mysql", and REPEAT step 2 and 3.

  6. Startup server

    • Change the current directory to MySQL's binary directory

    • Eg. Assume that the MySQL installed directory is "c:\MySQL\mysql" cd \MySQL\mysql\bin

    • Start the MySQL Database Server mysqld --console

  7. Start client

    • Change the current directory to MySQL's binary directory

    • Eg. Assume that the MySQL installed directory is "c:\MySQL\mysql" cd \MySQL\mysql\bin

    • Start a client as superuser "root" (-u), and prompt for password mysql -u root -p

  8. To change password: alter user 'root'@'localhost' identified by 'xxxx';

  9. To create new user: create user 'myuser'@'localhost' identified by 'xxxx';
    To grant permission to new user: grant all on *.* to 'myuser'@'localhost';

  10. change setting in code. go to src -> main -> java -> model -> authentication.java
    In line 26, change the user and password according to your mysql account that is set up above

Load script into database (mySQL) - assuming my sql is already set up:

  1. start server
    cd ..\mysql\bin
    mysqld --console

  2. start client
    cd ..\mysql\bin
    mysql -u myuser -p
    myuser is username. password will be requested.

  3. run script
    source ..\login\db.sql;