diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..a4ff7a2 --- /dev/null +++ b/.classpath @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..ffe60f3 --- /dev/null +++ b/.project @@ -0,0 +1,31 @@ + + + Administrative-Portal + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope new file mode 100644 index 0000000..81672d4 --- /dev/null +++ b/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7adc0fb --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,10 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=11 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..cbb67f3 --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..25e257c --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f527436 --- /dev/null +++ b/README.md @@ -0,0 +1,81 @@ +# Administrative-portal-for-Learner-s-Academy +## Project' Details +This project aims to design and develop a backend administrative portal for the Learner’s Academy using Java EE technologies. I developed it as a project of phase 2 for the Become a back-end expert course. +The goal of this project is to apply servlet, jsp and JDBC concepts. + +## Product Backlog: +1. Create database and tables. +2. Connect the database to the project. +3. Create models classes. +4. Create a database utility class to retrieve data. +5. Create login page. +6. Create JSP files for all pages of the project. +7. Create a servlet to get requests and send responses to the JSP files. +8. Add cookies. +9. Create a CSS file to format the contents. +10. Debug and Test the project. + +## Technologies and tools Used +• Servlet: to do the business logic and works a controller for the project. + +• JSP: to handle the presentation view. + +• SQL: to create and manage the database. + +• JDBC: to make operations on the database for the project. + +• CSS: to format the contents. + +• phpMyAdmin: to administrate and manage the database manually. + +• Eclipse: to write and run the code. + +• Tomcat: to run and deploy servlet application. + +## Flowcharts of The Application + +![Blank Diagram](https://user-images.githubusercontent.com/64940728/120771636-182e8e00-c528-11eb-92bb-f5856138c93f.png) + + +## Core concepts used in the project. +• Object-Oriented: used to create and model objects for users and their credentials. + +• Databases: used to store and retrieve data. + +• Data Sources: used to define a set of properties required to identify and access the database. + +• Collections: used some collections such arraylist to store collection of data. + +• Exception Handling: used to catch problems that arises in the code especially in I/O blocks. + +• Cookies: to store log-in data on the client browser. + + +## How to run the program +• clone project + +• Import the “database\database.sql” file to your database administration tool. + +• Go to “\src\main\webapp\META-INF\context.xml” file and open it. + +• Edit the database’ properties such as username, password and driverClassName to be suit to your database administration tool. + +• Now run program on a server. + +• To login you must enter admin for both username and password. + +Screenshots: + +![image](https://user-images.githubusercontent.com/64940728/120771774-47dd9600-c528-11eb-86c8-ee8a1b133a23.png) + +![image](https://user-images.githubusercontent.com/64940728/120771806-4e6c0d80-c528-11eb-97bb-8abe14d8560c.png) + +![image](https://user-images.githubusercontent.com/64940728/120771819-51ff9480-c528-11eb-98fe-39b7767b8de6.png) + +![image](https://user-images.githubusercontent.com/64940728/120771833-54fa8500-c528-11eb-9291-2ab6c81528f3.png) + +![image](https://user-images.githubusercontent.com/64940728/120771849-588e0c00-c528-11eb-89d0-fbc960d1562e.png) + +![image](https://user-images.githubusercontent.com/64940728/120771867-5c219300-c528-11eb-8aed-e8d137640817.png) + + diff --git a/build/classes/com/simplilearn/admin/AdminControllerServlet.class b/build/classes/com/simplilearn/admin/AdminControllerServlet.class new file mode 100644 index 0000000..1157c9a Binary files /dev/null and b/build/classes/com/simplilearn/admin/AdminControllerServlet.class differ diff --git a/build/classes/com/simplilearn/admin/DbRetrieve.class b/build/classes/com/simplilearn/admin/DbRetrieve.class new file mode 100644 index 0000000..f1a4fa4 Binary files /dev/null and b/build/classes/com/simplilearn/admin/DbRetrieve.class differ diff --git a/build/classes/com/simplilearn/admin/TestServlet.class b/build/classes/com/simplilearn/admin/TestServlet.class new file mode 100644 index 0000000..39c6130 Binary files /dev/null and b/build/classes/com/simplilearn/admin/TestServlet.class differ diff --git a/build/classes/com/simplilearn/models/Class.class b/build/classes/com/simplilearn/models/Class.class new file mode 100644 index 0000000..421c651 Binary files /dev/null and b/build/classes/com/simplilearn/models/Class.class differ diff --git a/build/classes/com/simplilearn/models/Student.class b/build/classes/com/simplilearn/models/Student.class new file mode 100644 index 0000000..604aaf4 Binary files /dev/null and b/build/classes/com/simplilearn/models/Student.class differ diff --git a/build/classes/com/simplilearn/models/Subject.class b/build/classes/com/simplilearn/models/Subject.class new file mode 100644 index 0000000..45c5ca5 Binary files /dev/null and b/build/classes/com/simplilearn/models/Subject.class differ diff --git a/build/classes/com/simplilearn/models/Teacher.class b/build/classes/com/simplilearn/models/Teacher.class new file mode 100644 index 0000000..049ed1b Binary files /dev/null and b/build/classes/com/simplilearn/models/Teacher.class differ diff --git a/database/administrative-portal.sql b/database/administrative-portal.sql new file mode 100644 index 0000000..d69b0ad --- /dev/null +++ b/database/administrative-portal.sql @@ -0,0 +1,192 @@ +-- phpMyAdmin SQL Dump +-- version 5.1.0 +-- https://www.phpmyadmin.net/ +-- +-- Host: 127.0.0.1:3307 +-- Generation Time: Jun 04, 2021 at 09:32 AM +-- Server version: 10.4.18-MariaDB +-- PHP Version: 8.0.3 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +START TRANSACTION; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- +-- Database: `administrative-portal` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `classes` +-- + +CREATE TABLE `classes` ( + `id` int(11) NOT NULL, + `section` int(55) NOT NULL, + `teacher` int(11) NOT NULL, + `subject` int(11) NOT NULL, + `time` varchar(44) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- +-- Dumping data for table `classes` +-- + +INSERT INTO `classes` (`id`, `section`, `teacher`, `subject`, `time`) VALUES +(1, 1, 1, 1, '9:00'), +(2, 3, 2, 2, '11:30'); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `students` +-- + +CREATE TABLE `students` ( + `id` int(11) NOT NULL, + `fname` varchar(55) NOT NULL, + `lname` varchar(55) NOT NULL, + `age` int(11) DEFAULT NULL, + `class` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- +-- Dumping data for table `students` +-- + +INSERT INTO `students` (`id`, `fname`, `lname`, `age`, `class`) VALUES +(1, 'Ali', 'Ahsan', 21, 1), +(2, 'Hassan', 'Ahmed', 23, 2), +(4, 'Gazi', 'Dani', 21, 1), +(5, 'Tony', 'Fadel', 18, 2), +(6, 'Lami', 'Saro', 24, 1), +(7, 'Yazen', 'Rawn', 24, 2); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `subjects` +-- + +CREATE TABLE `subjects` ( + `id` int(11) NOT NULL, + `name` varchar(55) NOT NULL, + `shortcut` varchar(50) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- +-- Dumping data for table `subjects` +-- + +INSERT INTO `subjects` (`id`, `name`, `shortcut`) VALUES +(1, 'English', 'ENG'), +(2, 'Mathematics', 'MATH'); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `teachers` +-- + +CREATE TABLE `teachers` ( + `id` int(11) NOT NULL, + `fname` varchar(55) NOT NULL, + `lname` varchar(55) NOT NULL, + `age` varchar(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- +-- Dumping data for table `teachers` +-- + +INSERT INTO `teachers` (`id`, `fname`, `lname`, `age`) VALUES +(1, 'Sami', 'Rashed', '55'), +(2, 'Rami', 'Sari', '66'); + +-- +-- Indexes for dumped tables +-- + +-- +-- Indexes for table `classes` +-- +ALTER TABLE `classes` + ADD PRIMARY KEY (`id`), + ADD KEY `subject_id` (`subject`), + ADD KEY `teacher_id` (`teacher`); + +-- +-- Indexes for table `students` +-- +ALTER TABLE `students` + ADD PRIMARY KEY (`id`), + ADD KEY `class_id` (`class`); + +-- +-- Indexes for table `subjects` +-- +ALTER TABLE `subjects` + ADD PRIMARY KEY (`id`); + +-- +-- Indexes for table `teachers` +-- +ALTER TABLE `teachers` + ADD PRIMARY KEY (`id`); + +-- +-- AUTO_INCREMENT for dumped tables +-- + +-- +-- AUTO_INCREMENT for table `classes` +-- +ALTER TABLE `classes` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; + +-- +-- AUTO_INCREMENT for table `students` +-- +ALTER TABLE `students` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8; + +-- +-- AUTO_INCREMENT for table `subjects` +-- +ALTER TABLE `subjects` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; + +-- +-- AUTO_INCREMENT for table `teachers` +-- +ALTER TABLE `teachers` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; + +-- +-- Constraints for dumped tables +-- + +-- +-- Constraints for table `classes` +-- +ALTER TABLE `classes` + ADD CONSTRAINT `subject_id` FOREIGN KEY (`subject`) REFERENCES `subjects` (`id`), + ADD CONSTRAINT `teacher_id` FOREIGN KEY (`teacher`) REFERENCES `teachers` (`id`); + +-- +-- Constraints for table `students` +-- +ALTER TABLE `students` + ADD CONSTRAINT `class_id` FOREIGN KEY (`class`) REFERENCES `classes` (`id`); +COMMIT; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/src/main/java/com/simplilearn/admin/AdminControllerServlet.java b/src/main/java/com/simplilearn/admin/AdminControllerServlet.java new file mode 100644 index 0000000..fe73d81 --- /dev/null +++ b/src/main/java/com/simplilearn/admin/AdminControllerServlet.java @@ -0,0 +1,238 @@ +package com.simplilearn.admin; + +import java.io.IOException; +import java.util.List; + +import javax.annotation.Resource; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.sql.DataSource; + +import com.simplilearn.models.Student; +import com.simplilearn.models.Subject; +import com.simplilearn.models.Teacher; +import com.simplilearn.models.Class; + +/** + * Servlet implementation class AdminControllerServlet + */ +@WebServlet("/AdminControllerServlet") +public class AdminControllerServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + private DbRetrieve dbRetrieve; + + @Resource(name = "jdbc_database") + private DataSource datasource; + + @Override + public void init() throws ServletException { + + super.init(); + + // create instance of db util, to pass in conn pool object + try { + dbRetrieve = new DbRetrieve(datasource); + + } catch (Exception e) { + throw new ServletException(e); + } + + } + + /** + * @see HttpServlet#HttpServlet() + */ + public AdminControllerServlet() { + super(); + // TODO Auto-generated constructor stub + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + + doGet(req, resp); + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse + * response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // TODO Auto-generated method stub + try { + + // read the "command" parameter + String command = request.getParameter("command"); + + if (command == null) { + command = "CLASSES"; + } + + // if no cookeies + if (!getCookies(request, response) && (!command.equals("LOGIN"))) { + + response.sendRedirect("/Administrative-Portal/login.jsp"); + } + + else { + + // if there is no command, how to handle + + // route the data to the appropriate method + switch (command) { + + case "STUDENTS": + studentsList(request, response); + break; + + case "TEACHERS": + teachersList(request, response); + break; + + case "SUBJECTS": + subjectList(request, response); + break; + + case "CLASSES": + classestList(request, response); + break; + + case "ST_LIST": + classStudentsList(request, response); + break; + + case "LOGIN": + login(request, response); + break; + + default: + classestList(request, response); + + } + } + } catch (Exception e) { + throw new ServletException(e); + } + // response.getWriter().append("Served at: ").append(request.getContextPath()); + } + + private void studentsList(HttpServletRequest request, HttpServletResponse response) throws Exception { + // get students from db util + List students = dbRetrieve.getStudents(); + + // add students to the request + request.setAttribute("STUDENT_LIST", students); + + // send it to the jsp view page + RequestDispatcher dispatcher = request.getRequestDispatcher("/list-students.jsp"); + dispatcher.forward(request, response); + + } + + private void teachersList(HttpServletRequest request, HttpServletResponse response) throws Exception { + // get students from db util + List teachers = dbRetrieve.getTeachers(); + + // add students to the request + request.setAttribute("TEACHERS_LIST", teachers); + + // send it to the jSP view page + RequestDispatcher dispatcher = request.getRequestDispatcher("/teachers-list.jsp"); + dispatcher.forward(request, response); + + } + + private void subjectList(HttpServletRequest request, HttpServletResponse response) throws Exception { + // get subjects from db util + List subjects = dbRetrieve.getSubjects(); + + // add subjects to the request + request.setAttribute("SUBJECTS_LIST", subjects); + + // send it to the jSP view page + RequestDispatcher dispatcher = request.getRequestDispatcher("/subjects-list.jsp"); + dispatcher.forward(request, response); + + } + + private void classestList(HttpServletRequest request, HttpServletResponse response) throws Exception { + // get subjects from db util + List classes = dbRetrieve.getClasses(); + + // add subjects to the request + request.setAttribute("CLASSES_LIST", classes); + + // send it to the jSP view page + RequestDispatcher dispatcher = request.getRequestDispatcher("/classes-list.jsp"); + dispatcher.forward(request, response); + + } + + private void login(HttpServletRequest request, HttpServletResponse response) throws Exception { + String username = request.getParameter("username"); + String password = request.getParameter("password"); + + if (username.toLowerCase().equals("admin") && password.toLowerCase().equals("admin")) { + + Cookie cookie = new Cookie(username, password); + + // Setting the maximum age to 1 day + cookie.setMaxAge(86400); // 86400 seconds in a day + + // Send the cookie to the client + response.addCookie(cookie); + classestList(request, response); + } else { + RequestDispatcher dispatcher = request.getRequestDispatcher("/login.jsp"); + dispatcher.forward(request, response); + } + + } + + private void classStudentsList(HttpServletRequest request, HttpServletResponse response) throws Exception { + + int classId = Integer.parseInt(request.getParameter("classId")); + String section = request.getParameter("section"); + String subject = request.getParameter("subject"); + + // get subjects from db util + List students = dbRetrieve.loadClassStudents(classId); + + // add subjects to the request + request.setAttribute("STUDENTS_LIST", students); + request.setAttribute("SECTION", section); + request.setAttribute("SUBJECT", subject); + + // send it to the jSP view page + RequestDispatcher dispatcher = request.getRequestDispatcher("/class-students.jsp"); + dispatcher.forward(request, response); + + } + + private boolean getCookies(HttpServletRequest request, HttpServletResponse response) throws Exception { + + boolean check = false; + Cookie[] cookies = request.getCookies(); + // Find the cookie of interest in arrays of cookies + for (Cookie cookie : cookies) { + + if (cookie.getName().equals("admin") && cookie.getValue().equals("admin")) { + check = true; + break; + } + + } + + + return check; + + } + +} diff --git a/src/main/java/com/simplilearn/admin/DbRetrieve.java b/src/main/java/com/simplilearn/admin/DbRetrieve.java new file mode 100644 index 0000000..330f92b --- /dev/null +++ b/src/main/java/com/simplilearn/admin/DbRetrieve.java @@ -0,0 +1,414 @@ +package com.simplilearn.admin; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import javax.sql.DataSource; + +import com.simplilearn.models.Student; +import com.simplilearn.models.Subject; +import com.simplilearn.models.Teacher; +import com.simplilearn.models.Class; + +public class DbRetrieve { + + private DataSource dataSource; + + public DbRetrieve(DataSource dataSource) { + this.dataSource = dataSource; + } + + public List getStudents() { + + List students = new ArrayList<>(); + + Connection myConn = null; + Statement myStmt = null; + ResultSet myRs = null; + + try { + + // get a connection + myConn = dataSource.getConnection(); + + // create sql stmt + String sql = "SELECT * FROM students"; + myStmt = myConn.createStatement(); + + // execute query + myRs = myStmt.executeQuery(sql); + + // process result + while (myRs.next()) { + + // retrieve data from result set row + int id = myRs.getInt("id"); + String firstName = myRs.getString("fname"); + String lastName = myRs.getString("lname"); + int age = myRs.getInt("age"); + int aclass = myRs.getInt("class"); + + // create new student object + Student tempStudent = new Student(id, firstName, lastName, age, aclass); + + // add it to the list of students + students.add(tempStudent); + + } + + } catch (Exception e) { + // TODO: handle exception + } finally { + // close JDBC objects + close(myConn, myStmt, myRs); + } + return students; + + } + + public List getTeachers() { + + List teachers = new ArrayList<>(); + + Connection myConn = null; + Statement myStmt = null; + ResultSet myRs = null; + + try { + + // get a connection + myConn = dataSource.getConnection(); + + // create sql stmt + String sql = "SELECT * FROM teachers"; + myStmt = myConn.createStatement(); + + // execute query + myRs = myStmt.executeQuery(sql); + + // process result + while (myRs.next()) { + + // retrieve data from result set row + int id = myRs.getInt("id"); + String firstName = myRs.getString("fname"); + String lastName = myRs.getString("lname"); + int age = myRs.getInt("age"); + + // create new student object + Teacher temp = new Teacher(id, firstName, lastName, age); + + // add it to the list of students + teachers.add(temp); + + } + + } catch (Exception e) { + // TODO: handle exception + } finally { + // close JDBC objects + close(myConn, myStmt, myRs); + } + return teachers; + + } + + public List getSubjects() { + + List subjects = new ArrayList<>(); + + Connection myConn = null; + Statement myStmt = null; + ResultSet myRs = null; + + try { + + // get a connection + myConn = dataSource.getConnection(); + + // create sql stmt + String sql = "SELECT * FROM subjects"; + myStmt = myConn.createStatement(); + + // execute query + myRs = myStmt.executeQuery(sql); + + // process result + while (myRs.next()) { + + // retrieve data from result set row + int id = myRs.getInt("id"); + String name = myRs.getString("name"); + String shortcut = myRs.getString("shortcut"); + + // create new student object + Subject temp = new Subject(id, name,shortcut); + + // add it to the list of students + subjects.add(temp); + + } + + } catch (Exception e) { + // TODO: handle exception + } finally { + // close JDBC objects + close(myConn, myStmt, myRs); + } + return subjects; + + } + + public List getClasses() { + + List classes = new ArrayList<>(); + + Connection myConn = null; + Statement myStmt = null; + ResultSet myRs = null; + + try { + + // get a connection + myConn = dataSource.getConnection(); + + // create sql stmt + String sql = "SELECT * FROM classes"; + myStmt = myConn.createStatement(); + + // execute query + myRs = myStmt.executeQuery(sql); + + // process result + while (myRs.next()) { + + // retrieve data from result set row + int id = myRs.getInt("id"); + int section = myRs.getInt("section"); + int subject = myRs.getInt("subject"); + int teacher = myRs.getInt("teacher"); + String time = myRs.getString("time"); + + Teacher tempTeacher = loadTeacher(teacher); + Subject tempSubject = loadSubject(subject); + + String teacher_name = tempTeacher.getFname() + " " + tempTeacher.getLname(); + + // create new student object + Class temp = new Class(id, section, teacher_name, tempSubject.getName(), time); + + // add it to the list of students + classes.add(temp); + + } + + } catch (Exception e) { + // TODO: handle exception + } finally { + // close JDBC objects + close(myConn, myStmt, myRs); + } + return classes; + + } + + public Teacher loadTeacher(int teacherId) { + + Teacher theTeacher = null; + + Connection myConn = null; + Statement myStmt = null; + ResultSet myRs = null; + + try { + + // get a connection + myConn = dataSource.getConnection(); + + // create sql stmt + String sql = "SELECT * FROM teachers WHERE id = " + teacherId; + myStmt = myConn.createStatement(); + + // execute query + myRs = myStmt.executeQuery(sql); + + // process result + while (myRs.next()) { + + // retrieve data from result set row + int id = myRs.getInt("id"); + String fname = myRs.getString("fname"); + String lname = myRs.getString("lname"); + int age = myRs.getInt("age"); + theTeacher = new Teacher(id, fname, lname, age); + + } + + } catch (Exception e) { + // TODO: handle exception + } finally { + // close JDBC objects + close(myConn, myStmt, myRs); + } + return theTeacher; + + } + + public Subject loadSubject(int subjectId) { + + Subject theSubject = null; + + Connection myConn = null; + Statement myStmt = null; + ResultSet myRs = null; + + try { + + // get a connection + myConn = dataSource.getConnection(); + + // create sql stmt + String sql = "SELECT * FROM subjects WHERE id = " + subjectId; + myStmt = myConn.createStatement(); + + // execute query + myRs = myStmt.executeQuery(sql); + + // process result + while (myRs.next()) { + + // retrieve data from result set row + int id = myRs.getInt("id"); + String name = myRs.getString("name"); + String shortcut = myRs.getString("shortcut"); + + theSubject = new Subject(id, name,shortcut); + + } + + } catch (Exception e) { + // TODO: handle exception + } finally { + // close JDBC objects + close(myConn, myStmt, myRs); + } + return theSubject; + + } + + public Class loadClass(int classId) { + + Class theClass = null; + + Connection myConn = null; + Statement myStmt = null; + ResultSet myRs = null; + + try { + + // get a connection + myConn = dataSource.getConnection(); + + // create sql stmt + String sql = "SELECT * FROM clasess WHERE id = " + classId; + myStmt = myConn.createStatement(); + + // execute query + myRs = myStmt.executeQuery(sql); + + // process result + while (myRs.next()) { + + // retrieve data from result set row + int id = myRs.getInt("id"); + int section = myRs.getInt("section"); + int subject = myRs.getInt("subject"); + int teacher = myRs.getInt("teacher"); + String time = myRs.getString("time"); + + Teacher tempTeacher = loadTeacher(teacher); + Subject tempSubject = loadSubject(subject); + + String teacher_name = tempTeacher.getFname() + " " + tempTeacher.getLname(); + + } + + } catch (Exception e) { + // TODO: handle exception + } finally { + // close JDBC objects + close(myConn, myStmt, myRs); + } + return theClass; + + } + + public List loadClassStudents(int classId) { + + List students = new ArrayList<>(); + + Connection myConn = null; + Statement myStmt = null; + ResultSet myRs = null; + + try { + + // get a connection + myConn = dataSource.getConnection(); + + // create sql stmt + String sql = "SELECT * FROM students WHERE class = " + classId; + myStmt = myConn.createStatement(); + + // execute query + myRs = myStmt.executeQuery(sql); + + // process result + while (myRs.next()) { + + // retrieve data from result set row + int id = myRs.getInt("id"); + String firstName = myRs.getString("fname"); + String lastName = myRs.getString("lname"); + int age = myRs.getInt("age"); + int aclass = myRs.getInt("class"); + + // create new student object + Student tempStudent = new Student(id, firstName, lastName, age, aclass); + students.add(tempStudent); + + } + + } catch (Exception e) { + // TODO: handle exception + } finally { + // close JDBC objects + close(myConn, myStmt, myRs); + } + return students; + + } + + private void close(Connection myConn, Statement myStmt, ResultSet myRs) { + + try { + if (myRs != null) { + myRs.close(); + } + if (myStmt != null) { + myStmt.close(); + } + if (myConn != null) { + myConn.close(); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + } + +} diff --git a/src/main/java/com/simplilearn/admin/TestServlet.java b/src/main/java/com/simplilearn/admin/TestServlet.java new file mode 100644 index 0000000..0ba061e --- /dev/null +++ b/src/main/java/com/simplilearn/admin/TestServlet.java @@ -0,0 +1,88 @@ +package com.simplilearn.admin; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; + +import javax.annotation.Resource; +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.sql.DataSource; + +/** + * Servlet implementation class TestServlet + */ +@WebServlet("/TestServlet") +public class TestServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + //Define datasource/connection pool for reference + + @Resource(name="jdbc_database") + private DataSource dataSource; + + + + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + + // Set the printwriter + PrintWriter out = response.getWriter(); + response.setContentType("text/plain"); + + // establish connection to the DB + Connection myConn = null; + Statement myStmt = null; + ResultSet myRs = null; + + try { + + myConn = dataSource.getConnection(); + //create a sql statement + String sql = "select * from students"; + myStmt = myConn.createStatement(); + + + //execute the sql statement + myRs = myStmt.executeQuery(sql); + + //process the resultset + while(myRs.next()) { + String fname = myRs.getString("fname"); + out.println(fname); + + } + + + + } + catch(Exception e) { + e.printStackTrace(); + } + + + + + + + + + + + + + + + + } + +} diff --git a/src/main/java/com/simplilearn/models/Class.java b/src/main/java/com/simplilearn/models/Class.java new file mode 100644 index 0000000..a7ce715 --- /dev/null +++ b/src/main/java/com/simplilearn/models/Class.java @@ -0,0 +1,56 @@ +package com.simplilearn.models; + +public class Class { + + private int id; + private int section; + private String teacher; + private String subject; + private String time; + + + + public Class(int id, int section, String teacher, String subject, String time) { + super(); + this.id = id; + this.section = section; + this.teacher = teacher; + this.subject = subject; + this.time = time; + } + + + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + public int getSection() { + return section; + } + public void setSection(int section) { + this.section = section; + } + public String getTeacher() { + return teacher; + } + public void setTeacher(String teacher) { + this.teacher = teacher; + } + public String getSubject() { + return subject; + } + public void setSubject(String subject) { + this.subject = subject; + } + public String getTime() { + return time; + } + public void setTime(String time) { + this.time = time; + } + + + +} diff --git a/src/main/java/com/simplilearn/models/Student.java b/src/main/java/com/simplilearn/models/Student.java new file mode 100644 index 0000000..ed40542 --- /dev/null +++ b/src/main/java/com/simplilearn/models/Student.java @@ -0,0 +1,64 @@ +package com.simplilearn.models; + +public class Student { + + private int id; + private String fname; + private String lname; + private int age; + private int aclass; + + + + + public Student(int id, String fname, String lname, int age, int aclass) { + super(); + this.id = id; + this.fname = fname; + this.lname = lname; + this.age = age; + this.aclass = aclass; + } + + + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + public String getFname() { + return fname; + } + public void setFname(String fname) { + this.fname = fname; + } + public String getLname() { + return lname; + } + public void setLname(String lname) { + this.lname = lname; + } + public int getAge() { + return age; + } + public void setAge(int age) { + this.age = age; + } + public int getAclass() { + return aclass; + } + public void setAclass(int aclass) { + this.aclass = aclass; + } + + + @Override + public String toString() { + return "Student [id=" + id + ", fname=" + fname + ", lname=" + lname + ", age=" + age + ", aclass=" + aclass + + "]"; + } + + + +} diff --git a/src/main/java/com/simplilearn/models/Subject.java b/src/main/java/com/simplilearn/models/Subject.java new file mode 100644 index 0000000..1b41614 --- /dev/null +++ b/src/main/java/com/simplilearn/models/Subject.java @@ -0,0 +1,43 @@ +package com.simplilearn.models; + +public class Subject { + + private int id; + private String name; + private String shortcut; + + public Subject(int id, String name, String shortcut ) { + super(); + this.id = id; + this.name = name; + this.shortcut = shortcut; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getShortcut() { + return shortcut; + } + + public void setShortcut(String shortcut) { + this.shortcut = shortcut; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + + +} diff --git a/src/main/java/com/simplilearn/models/Teacher.java b/src/main/java/com/simplilearn/models/Teacher.java new file mode 100644 index 0000000..ecbaa44 --- /dev/null +++ b/src/main/java/com/simplilearn/models/Teacher.java @@ -0,0 +1,52 @@ +package com.simplilearn.models; + +public class Teacher { + + private int id; + private String fname; + private String lname; + private int age; + + public Teacher(int id, String fname, String lname, int age) { + super(); + this.id = id; + this.fname = fname; + this.lname = lname; + this.age = age; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getFname() { + return fname; + } + + public void setFname(String fname) { + this.fname = fname; + } + + public String getLname() { + return lname; + } + + public void setLname(String lname) { + this.lname = lname; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + + +} diff --git a/src/main/webapp/META-INF/MANIFEST.MF b/src/main/webapp/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/src/main/webapp/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/src/main/webapp/META-INF/context.xml b/src/main/webapp/META-INF/context.xml new file mode 100644 index 0000000..0147a5a --- /dev/null +++ b/src/main/webapp/META-INF/context.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/lib/javax.servlet.jsp.jstl-1.2.1.jar b/src/main/webapp/WEB-INF/lib/javax.servlet.jsp.jstl-1.2.1.jar new file mode 100644 index 0000000..a86a365 Binary files /dev/null and b/src/main/webapp/WEB-INF/lib/javax.servlet.jsp.jstl-1.2.1.jar differ diff --git a/src/main/webapp/WEB-INF/lib/javax.servlet.jsp.jstl-api-1.2.1.jar b/src/main/webapp/WEB-INF/lib/javax.servlet.jsp.jstl-api-1.2.1.jar new file mode 100644 index 0000000..4b3b433 Binary files /dev/null and b/src/main/webapp/WEB-INF/lib/javax.servlet.jsp.jstl-api-1.2.1.jar differ diff --git a/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.23.jar b/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.23.jar new file mode 100644 index 0000000..1e0cb19 Binary files /dev/null and b/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.23.jar differ diff --git a/src/main/webapp/WEB-INF/lib/protobuf-java-3.11.4.jar b/src/main/webapp/WEB-INF/lib/protobuf-java-3.11.4.jar new file mode 100644 index 0000000..7224d23 Binary files /dev/null and b/src/main/webapp/WEB-INF/lib/protobuf-java-3.11.4.jar differ diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..e50d190 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,10 @@ + + + Administrative-Portal + + + AdminControllerServlet + index.jsp + index.html + + \ No newline at end of file diff --git a/src/main/webapp/class-students.jsp b/src/main/webapp/class-students.jsp new file mode 100644 index 0000000..6c29839 --- /dev/null +++ b/src/main/webapp/class-students.jsp @@ -0,0 +1,57 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> + + + + + +Students of a Class + + + +
+ + + +
+ + +
+ + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
First NameLast Nameage
${tempStudent.fname}${tempStudent.lname}${tempStudent.age}
+
+
+
+ + + \ No newline at end of file diff --git a/src/main/webapp/classes-list.jsp b/src/main/webapp/classes-list.jsp new file mode 100644 index 0000000..6df6466 --- /dev/null +++ b/src/main/webapp/classes-list.jsp @@ -0,0 +1,69 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> + + + + +List of Classes + + + +
+ + + +
+ + +
+ + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SectionSubjectTeacherTimeList of Students
${tempClass.section}${tempClass.subject}${tempClass.teacher}${tempClass.time}List
+
+
+
+ + + \ No newline at end of file diff --git a/src/main/webapp/css/add-student-style.css b/src/main/webapp/css/add-student-style.css new file mode 100644 index 0000000..62fb41a --- /dev/null +++ b/src/main/webapp/css/add-student-style.css @@ -0,0 +1,43 @@ +form { + margin-top: 10px; +} + +label { + font-size: 16px; + width: 100px; + display: block; + text-align: right; + margin-right: 10px; + margin-top: 8px; + margin-bottom: 8px; +} + +input { + width: 250px; + border: 1px solid #666; + border-radius: 5px; + padding: 4px; + font-size: 16px; +} + +.save { + font-weight: bold; + width: 130px; + padding: 5px 10px; + margin-top: 30px; + background: #cccccc; +} + +table { + border-style:none; + width:50%; +} + +tr:nth-child(even) {background: #FFFFFF} +tr:nth-child(odd) {background: #FFFFFF} + +tr { + border-style:none; + text-align:left; +} + diff --git a/src/main/webapp/css/background.jpg b/src/main/webapp/css/background.jpg new file mode 100644 index 0000000..604e7a5 Binary files /dev/null and b/src/main/webapp/css/background.jpg differ diff --git a/src/main/webapp/css/login.css b/src/main/webapp/css/login.css new file mode 100644 index 0000000..fa93cc9 --- /dev/null +++ b/src/main/webapp/css/login.css @@ -0,0 +1,42 @@ +Body { + font-family: Calibri, Helvetica, sans-serif; + background-color: pink; + +} +button { + justify-content: center; + background-color: #4CAF50; + width: 100%; + color: white; + padding: 15px; + margin: 10px 0px; + border: none; + cursor: pointer; + } + + form { + border: 1.4px solid black; + width: 45%; + margin: 0 auto; + } + input[type=text], input[type=password] { + justify-content: center; + width: 100%; + margin: 8px 0; + padding: 12px 20px; + display: inline-block; + border: 2px solid green; + box-sizing: border-box; + } + button:hover { + opacity: 0.7; + } + + + + .container { + + justify-content: center; + padding: 15px; + background-color: #FFF8DC; + } \ No newline at end of file diff --git a/src/main/webapp/css/style.css b/src/main/webapp/css/style.css new file mode 100644 index 0000000..4c3a8d7 --- /dev/null +++ b/src/main/webapp/css/style.css @@ -0,0 +1,105 @@ +html, body{ + + padding:0px; + font-family:Verdana, Arial, Helvetica, sans-serif; + margin-left: 103px; /* Same as the width of the sidenav */ +} + +table { + border-collapse:collapse; + border:1px solid gray; + font-family: Tahoma,Verdana,Segoe,sans-serif; + width:72%; + +} + +th { + border-bottom:1px solid gray; + background:none repeat scroll 0 0 #0775d3; + padding:10px; + color: #FFFFFF; +} + +tr { + border-top:1px solid gray; + text-align:center; +} + +tr:nth-child(even) {background: #FFFFFF} +tr:nth-child(odd) {background: #BBBBBB} + +#wrapper {width: 100%; text-align: center; } +#header {width: 72%; background: #0775d3; margin-top: 0px; padding:5px 0px 15px 0px;} +#header h3 {width: 100%; margin:auto; color: #FFFFFF;} +#container {width: 100%; margin:auto} +#container h3 {color: #000;} +#container #content {margin-top: 20px;} + +.add-student-button { + border: 1px solid #666; + border-radius: 5px; + padding: 4px; + font-size: 12px; + font-weight: bold; + width: 120px; + padding: 5px 10px; + + margin-bottom: 15px; + background: #cccccc; +} + + + +.sidenav { + height: 100%; + width: 200px; + border-color: #FFFFFF; + position: fixed; + z-index: 1; + top: 0; + left: 0; + background-color: #000080; + overflow-x: hidden; + padding-top: 20px; +} + +.sidenav a { + padding: 6px 6px 6px 32px; + text-decoration: none; + font-size: 25px; + color: white; + display: block; +} + +.sidenav a:hover { + color: blue; +} + +@media screen and (max-height: 450px) { + .sidenav {padding-top: 15px;} + .sidenav a {font-size: 18px;} +} + +#page{ + + height: 100%; + + +} + + +#logo{ + font-family: 'Trebuchet MS', sans-serif; + text-align: center; + color: white; + +} + +.bar-item{ + + + border-color: #FFFFFF; + border-width: 3px; + border-bottom: .5px solid rgba(255, 255, 255, 0.247); + +} \ No newline at end of file diff --git a/src/main/webapp/left-list.jsp b/src/main/webapp/left-list.jsp new file mode 100644 index 0000000..740ef8f --- /dev/null +++ b/src/main/webapp/left-list.jsp @@ -0,0 +1,35 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> + +
+ + + + + + + + + + + + + + + + + + + + + + + Classes + Subjects + Teachers + Students + Log out + +
+ diff --git a/src/main/webapp/list-students.jsp b/src/main/webapp/list-students.jsp new file mode 100644 index 0000000..ca4c380 --- /dev/null +++ b/src/main/webapp/list-students.jsp @@ -0,0 +1,58 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> + + + + + +List of Students + + + +
+ + + +
+ + +
+ + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
First NameLast Nameage
${tempStudent.fname}${tempStudent.lname}${tempStudent.age}
+
+
+
+ + + \ No newline at end of file diff --git a/src/main/webapp/login.jsp b/src/main/webapp/login.jsp new file mode 100644 index 0000000..8a95a2d --- /dev/null +++ b/src/main/webapp/login.jsp @@ -0,0 +1,33 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> + + + + + +Login + + + + +

Admin Login

+
+
+ + +
+ +
+ +
+ +
+ +
+ Remember me + +
+
+ + + + \ No newline at end of file diff --git a/src/main/webapp/subjects-list.jsp b/src/main/webapp/subjects-list.jsp new file mode 100644 index 0000000..e4f7cc7 --- /dev/null +++ b/src/main/webapp/subjects-list.jsp @@ -0,0 +1,54 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> + + + + +List of Teachers + + + +
+ + + +
+ + +
+ + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
NameShortcut
${tempSubject.name}${tempSubject.shortcut}
+
+
+
+ + + \ No newline at end of file diff --git a/src/main/webapp/teachers-list.jsp b/src/main/webapp/teachers-list.jsp new file mode 100644 index 0000000..7434c8f --- /dev/null +++ b/src/main/webapp/teachers-list.jsp @@ -0,0 +1,56 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> + + + + +List of Teachers + + + +
+ + + +
+ + +
+ + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
First NameLast Nameage
${tempStudent.fname}${tempStudent.lname}${tempStudent.age}
+
+
+
+ + + \ No newline at end of file