diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..aa00ffa
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..82dbec8
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..288b36b
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DOCS.md b/DOCS.md
new file mode 100644
index 0000000..f833639
--- /dev/null
+++ b/DOCS.md
@@ -0,0 +1,53 @@
+## Project Name - MVC APP
+
+## Technologies Used
+
+- Java
+- Servlets
+- JSP (JavaServer Pages)
+- HTML
+- CSS
+- Bootstrap
+- Apache Tomcat
+- XAMPP
+- Maven
+
+## Description
+
+This project is an MVC web application built using Java Servlets and JSP (JavaServer Pages). It follows the Model-View-Controller (MVC) architecture and includes separate controllers, models, and views packages. The project utilizes the Apache Tomcat server for running the web application locally. XAMPP is used for managing the MySQL database. Maven is used as the build tool to manage dependencies and packages.
+
+## Setup Instructions
+
+- Fork the repository
+
+- Clone the repository to your local machine using the following command:
+$ git clone git@github.com:Zshiva/Java-Assignment.git
+
+## Import the project into IntelliJ IDEA:
+
+- Open IntelliJ IDEA.
+- Click on "Open or Import" and navigate to the project's root folder.
+- Select the pom.xml file and click "Open" to import the project.
+
+## Configure the Apache Tomcat server:
+
+- Download and install Apache Tomcat (if not already installed).
+- Add the Apache Tomcat server in IntelliJ IDEA:
+- Open IntelliJ IDEA.
+- Click on "Configure" > "Settings" > "Build, Execution, Deployment" > "Application Servers".
+- Click on the "+" icon and select "Tomcat Server" > "Local".
+- Choose the Tomcat installation directory and click "OK".
+- Configure the database connection using XAMPP:
+
+### Install XAMPP and start the Apache and MySQL services.
+
+## Project Structure
+- src/main/java: Contains the Java classes.
+- Controller: Contains the Servlet classes handling HTTP requests and responses.
+- Model: Contains the Java classes representing the data models.
+
+- src/main/webapp: Contains the static resources (HTML, CSS, JavaScript) and JSP files.
+- Views: Contains the JSP files for rendering the views.
+
+## Run the project locally:
+- The web application will be accessible through http://localhost:8080/Java-Assignment/Views/registration.jsp
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..33fa41d
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,43 @@
+
+ 4.0.0
+ org.example
+ JavaAssignment
+ war
+ 1.0-SNAPSHOT
+ JavaAssignment Maven Webapp
+ http://maven.apache.org
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+ javax.servlet
+ javax.servlet-api
+ 3.1.0
+ provided
+
+
+
+ 17
+ 17
+
+
+ JavaAssignment
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+ 3.3.2
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.11.0
+
+
+
+
diff --git a/src/main/java/Controller/LogOutServlet.java b/src/main/java/Controller/LogOutServlet.java
new file mode 100644
index 0000000..d77498a
--- /dev/null
+++ b/src/main/java/Controller/LogOutServlet.java
@@ -0,0 +1,21 @@
+package Controller;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.io.IOException;
+
+@WebServlet("/Views/logout")
+public class LogOutServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ HttpSession session = request.getSession();
+ session.invalidate();
+ response.sendRedirect("login.jsp");
+ }
+}
diff --git a/src/main/java/Controller/LoginServlet.java b/src/main/java/Controller/LoginServlet.java
new file mode 100644
index 0000000..a451603
--- /dev/null
+++ b/src/main/java/Controller/LoginServlet.java
@@ -0,0 +1,47 @@
+package Controller;
+
+import Models.Database.SetUpAndConnectDb;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.io.IOException;
+import java.sql.*;
+
+@WebServlet("/Views/login")
+public class LoginServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ String useQuery = "USE WEBAPP";
+ String email = request.getParameter("email");
+ String password = request.getParameter("password");
+ HttpSession session = request.getSession();
+
+ try {
+ Connection conn = new SetUpAndConnectDb().setupAndConnectionDb();
+ Statement st = conn.createStatement();
+ st.executeUpdate(useQuery);
+ PreparedStatement ps = conn.prepareStatement("select * from users where email = ? and password = ?");
+ ps.setString(1, email);
+ ps.setString(2, password);
+ ResultSet rs = ps.executeQuery();
+ if(rs.next()){
+ session.setAttribute("username", rs.getString("username"));
+ response.sendRedirect("home.jsp");
+ }else{
+ request.setAttribute("status","failed");
+ RequestDispatcher dispatcher = request.getRequestDispatcher("login.jsp");
+ dispatcher.forward(request,response);
+ }
+
+ } catch (SQLException E) {
+ E.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/Controller/RegistrationServlet.java b/src/main/java/Controller/RegistrationServlet.java
new file mode 100644
index 0000000..007e733
--- /dev/null
+++ b/src/main/java/Controller/RegistrationServlet.java
@@ -0,0 +1,56 @@
+package Controller;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import Models.Database.SetUpAndConnectDb;
+
+@WebServlet("/Views/register")
+public class RegistrationServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ String useQuery = "USE WEBAPP";
+
+ String name = request.getParameter("name");
+ String username = request.getParameter("username");
+ String email = request.getParameter("email");
+ String password = request.getParameter("password");
+ String address = request.getParameter("address");
+ RequestDispatcher dispatcher = null;
+
+ try{
+ Connection conn = new SetUpAndConnectDb().setupAndConnectionDb();
+ Statement st = conn.createStatement();
+ st.executeUpdate(useQuery);
+ PreparedStatement ps = conn.prepareStatement("Insert into users(name, username, email, password, address) values(?,?,?,?,?)");
+ ps.setString(1, name);
+ ps.setString(2, username);
+ ps.setString(3, email);
+ ps.setString(4, password);
+ ps.setString(5, address);
+
+ int rowcount = ps.executeUpdate();
+ dispatcher = request.getRequestDispatcher("registration.jsp");
+ if(rowcount > 0){
+ request.setAttribute("status", "success");
+ }else{
+ request.setAttribute("status", "failed");
+ }
+ dispatcher.forward(request, response);
+
+ }catch(SQLException e){
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/Models/Database/CreateTable.java b/src/main/java/Models/Database/CreateTable.java
new file mode 100644
index 0000000..6005753
--- /dev/null
+++ b/src/main/java/Models/Database/CreateTable.java
@@ -0,0 +1,40 @@
+package Models.Database;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+
+public class CreateTable {
+ private Connection connection;
+ private String usequery = "USE WEBAPP;";
+
+ public CreateTable(Connection connection) {
+ this.connection = connection;
+ this.createUserTable();
+ }
+ public static void main(String[] args) throws SQLException {
+ CreateTable ct= new CreateTable(new SetUpAndConnectDb().setupAndConnectionDb());
+
+ }
+ // Created User Table to store user data
+ public void createUserTable() {
+ String sql = "CREATE TABLE IF NOT EXISTS users (" +
+ "id INT AUTO_INCREMENT PRIMARY KEY," +
+ "name VARCHAR(50) NOT NULL," +
+ "username VARCHAR(50) NOT NULL," +
+ "email VARCHAR(100) NOT NULL," +
+ "password VARCHAR(100) NOT NULL," +
+ "address VARCHAR(100) NOT NULL" +
+ ");";
+
+ try {
+ Statement s1 = this.connection.createStatement();
+ s1.executeUpdate(this.usequery);
+ s1.executeUpdate(sql);
+ } catch (SQLException var3) {
+ var3.printStackTrace();
+ }
+ }
+}
+
diff --git a/src/main/java/Models/Database/SetUpAndConnectDb.java b/src/main/java/Models/Database/SetUpAndConnectDb.java
new file mode 100644
index 0000000..2af7eb9
--- /dev/null
+++ b/src/main/java/Models/Database/SetUpAndConnectDb.java
@@ -0,0 +1,34 @@
+package Models.Database;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class SetUpAndConnectDb {
+ private Connection connection;
+ private String url = "jdbc:mysql://localhost:3306/";
+ private String username = "root";
+ private String password = "";
+
+ public static void main(String[] args) throws SQLException {
+ SetUpAndConnectDb st = new SetUpAndConnectDb();
+ st.setupAndConnectionDb();
+ }
+
+ public Connection setupAndConnectionDb() throws SQLException {
+ try {
+ Class.forName("com.mysql.cj.jdbc.Driver");
+ this.connection = DriverManager.getConnection(this.url, this.username, this.password);
+ String query = "CREATE DATABASE IF NOT EXISTS WEBAPP";
+ Statement st = this.connection.createStatement();
+ st.executeUpdate(query);
+
+ } catch (ClassNotFoundException var1) {
+ System.out.println(var1);
+ } catch (SQLException var2) {
+ System.out.println(var2);
+ }
+ return this.connection;
+ }
+}
diff --git a/src/main/java/Models/Entities/User.java b/src/main/java/Models/Entities/User.java
new file mode 100644
index 0000000..0cd0ade
--- /dev/null
+++ b/src/main/java/Models/Entities/User.java
@@ -0,0 +1,4 @@
+package Models.Entities;
+
+public class User {
+}
diff --git a/src/main/webapp/Views/home.jsp b/src/main/webapp/Views/home.jsp
new file mode 100644
index 0000000..1b82139
--- /dev/null
+++ b/src/main/webapp/Views/home.jsp
@@ -0,0 +1,77 @@
+<%
+if(session.getAttribute("username") == null){
+response.sendRedirect("login.jsp");
+}
+%>
+
+
+
+
+
+
+Home Page
+
+
+
+
+
+
+
+
+
+
+
+
+
Welcome, <%= session.getAttribute("username") %>
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/Views/login.jsp b/src/main/webapp/Views/login.jsp
new file mode 100644
index 0000000..9862b7e
--- /dev/null
+++ b/src/main/webapp/Views/login.jsp
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+Login Form
+
+
+
+
+
+
+
+
+">
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/Views/registration.jsp b/src/main/webapp/Views/registration.jsp
new file mode 100644
index 0000000..d0516bd
--- /dev/null
+++ b/src/main/webapp/Views/registration.jsp
@@ -0,0 +1,77 @@
+<%@ page import="java.util.*" %>
+<%@ page import="javax.servlet.http.*" %>
+
+
+
+
+
+
+ Registration Form
+
+
+
+
+
+
+
+
+ ">
+
+
+
+
+
Registration Form
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/Views/style.css b/src/main/webapp/Views/style.css
new file mode 100644
index 0000000..279d2a6
--- /dev/null
+++ b/src/main/webapp/Views/style.css
@@ -0,0 +1,28 @@
+/* Custom styles */
+body {
+ background-color: #f7f7f7;
+}
+
+.custom-card-width {
+ max-width: 500px;
+ width: 90%;
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
+ animation: fadeIn 1s ease-in-out;
+
+}
+
+@keyframes fadeIn {
+ 0% {
+ opacity: 0;
+ }
+ 100% {
+ opacity: 1;
+ }
+}
+
+
+@media (max-width: 576px) {
+ .custom-card-width {
+ max-width: 100%;
+ }
+}
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..f06cbb1
--- /dev/null
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,12 @@
+
+
+
+ Archetype Created Web Application
+
+
+ registration.jsp
+
+
+