Mini Project
Mini Project
Project Objective: Create an Online quiz portal, where users can explore
multiple quiz, attempt the quiz, and save their position on the learder board.
package com.demo.controller;
import java.io.IOException;
import java.util.List;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import com.demo.model.QuizListBean;
import com.demo.service.QuizListServiceImpl;
import com.demo.service.QuizListservice;
import jakarta.servlet.RequestDispatcher;
/**
* Servlet implementation class DashboardServletClass
*/
public class DashboardServletClass extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public DashboardServletClass() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
QuizListservice quizService=new QuizListServiceImpl();
List<QuizListBean> TotalQuizlist=quizService.retrive();
request.setAttribute("TotalQuizlist", TotalQuizlist);
if(!TotalQuizlist.isEmpty()) {
RequestDispatcher dispatcher=
request.getRequestDispatcher("Dashboard.jsp");
dispatcher.forward(request, response);
}else {
RequestDispatcher dispatcher=
request.getRequestDispatcher("error.jsp");
dispatcher.forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request,
HttpServletResponse response)
*/
// protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// doGet(request, response);
// }
package com.demo.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import com.demo.entites.QuizList;
import com.demo.service.QuizListServiceImpl;
import com.demo.service.QuizListservice;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
* Servlet implementation class DeleteQuizServlet
*/
public class DeleteQuizServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public DeleteQuizServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
String quizid=request.getParameter("quizId");
QuizList quiz=new QuizList();
quiz.setQuiz_id(quizid);
PrintWriter out=response.getWriter();
QuizListservice quizservice=new QuizListServiceImpl();
boolean delete;
try {
delete = quizservice.DeleteById(quiz);
if(delete) {
RequestDispatcher
rd=request.getRequestDispatcher("/dashboardpage");
rd.forward(request, response);
}
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
package com.demo.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;
import com.demo.entites.QuizList;
import com.demo.model.QuizListBean;
import com.demo.service.QuizListServiceImpl;
import com.demo.service.QuizListservice;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
* Servlet implementation class GetById
*/
public class GetById extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public GetById() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
String quizId=request.getParameter("quizId");
QuizList quiz=new QuizList();
quiz.setQuiz_id(quizId);
PrintWriter out=response.getWriter();
QuizListservice quizservice=new QuizListServiceImpl();
List<QuizListBean> TotalQuizlist;
try {
TotalQuizlist = quizservice.getById(quiz);
request.setAttribute("TotalQuizlist", TotalQuizlist);
if(!TotalQuizlist.isEmpty()) {
RequestDispatcher dispatcher=
request.getRequestDispatcher("Edit.jsp");
dispatcher.forward(request, response);
}else {
RequestDispatcher dispatcher=
request.getRequestDispatcher("error.jsp");
dispatcher.forward(request, response);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.demo.controller;
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import com.demo.entites.Users;
import com.demo.exception.AuthenticationException;
import com.demo.service.UserServiceImpl;
import com.demo.service.UsersService;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.http.HttpSession;
/**
* Servlet implementation class LoginServletClass
*/
public class LoginServletClass extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public LoginServletClass() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
String username=request.getParameter("username");
String password=request.getParameter("password");
package com.demo.controller;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import com.demo.model.QuestionListBean;
import com.demo.service.QuestionServiceImpl;
import com.demo.service.Questionsservice;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
* Servlet implementation class QuestionListServletClass
*/
public class QuestionListServletClass extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public QuestionListServletClass() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
Questionsservice quizService=new QuestionServiceImpl();
try {
List<QuestionListBean> TotalQuestuinlist =
quizService.retrive();
request.setAttribute("TotalQuizlist", TotalQuestuinlist);
if(!TotalQuestuinlist.isEmpty()) {
RequestDispatcher dispatcher=
request.getRequestDispatcher("questions.jsp");
dispatcher.forward(request, response);
}else {
RequestDispatcher dispatcher=
request.getRequestDispatcher("error.jsp");
dispatcher.forward(request, response);
}
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
package com.demo.controller;
import java.io.IOException;
import com.demo.DAO.QuestionDAOImpl;
import com.demo.DAO.QuestionsDAO;
import com.demo.entites.Quizz;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
* Servlet implementation class SaveQuestionsServlet
*/
public class SaveQuestionsServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public SaveQuestionsServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
String question=request.getParameter("questions");
String op1=request.getParameter("option1");
String op2=request.getParameter("option2");
String op3=request.getParameter("option3");
String op4=request.getParameter("option4");
String crctans=request.getParameter("correctAnswer");
String quizId=request.getParameter("quizId");
String wt=request.getParameter("weightage");
try {
// Call a DAO or service method to save the quiz question to the
database
QuestionsDAO quizDAO = new QuestionDAOImpl();
boolean isSaved = quizDAO.create(quiz);
if (isSaved) {
response.sendRedirect("Dashboard.jsp");
} else {
response.sendRedirect("error.jsp");
}
} catch (Exception e) {
e.printStackTrace();
response.sendRedirect("error.jsp");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request,
HttpServletResponse response)
*/
// protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// // TODO Auto-generated method stub
// doGet(request, response);
// }
package com.demo.controller;
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import com.demo.entites.QuizList;
import com.demo.service.QuizListServiceImpl;
import com.demo.service.QuizListservice;
/**
* Servlet implementation class updateServletClass
*/
public class updateServletClass extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public updateServletClass() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
String quizid=request.getParameter("quizId");
String quizName=request.getParameter("quizName");
String quizcatogoty=request.getParameter("quizCategory");
String quizmarks=request.getParameter("quizTotalmarks");
int marks=Integer.parseInt(quizmarks);
QuizList quiz=new QuizList();
quiz.setQuiz_id(quizid);
quiz.setQuizes(quizName);
quiz.setCategories(quizcatogoty);
quiz.setTotalmarks(marks);
QuizListservice quizservice=new QuizListServiceImpl();
try {
boolean update=false;
update=quizservice.update(quiz);
if(update) {
RequestDispatcher
rd=request.getRequestDispatcher("Dashboard.jsp");
rd.forward(request, response);
}
}catch(Exception e) {
e.printStackTrace();
}
}
package com.demo.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import com.demo.entites.Users;
import com.demo.exception.AuthenticationException;
import com.demo.model.QuizListBean;
import com.demo.service.QuizListServiceImpl;
import com.demo.service.QuizListservice;
import com.demo.service.UserServiceImpl;
import com.demo.service.UsersService;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.http.HttpSession;
/**
* Servlet implementation class userLoginServlet
*/
public class userLoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public userLoginServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
String username=request.getParameter("username");
String password=request.getParameter("password");
Users users=new Users();
users.setUsername(username);
users.setPassword(password);
PrintWriter out=response.getWriter();
UsersService userService=new UserServiceImpl();
try {
boolean auth=userService.authenticatenormalUser(users);
if(auth) {
request.getRequestDispatcher("error.jsp");
dispatcher.forward(request, response);
}
}
}catch(AuthenticationException e) {
out.println("<font color=red> Login Failed");
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
package com.demo.DAO;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.demo.DAO.QuestionsDAO;
import com.demo.entites.QuizList;
import com.demo.entites.Quizz;
import com.demo.helper.ConnectionManager;
@Override
public List<Quizz> retrive() throws ClassNotFoundException,
SQLException {
Connection connection =connectionManager.openConnection();
PreparedStatement
prepared=connection.prepareStatement("select
q.questions,q.option1,q.option2,q.option3,q.option4,q.s_no,q.correct_answer,
q.quiz_id from quizz q inner join quiz_list q1 on q.quiz_id=q1.quiz_id");
List<Quizz> question=new ArrayList<>();
Quizz q=new Quizz();
ResultSet rs=prepared.executeQuery();
while(rs.next()) {
q.setQuestions(rs.getString(1));
q.setOption1(rs.getString(2));
q.setOption2(rs.getString(3));
q.setOption4(rs.getString(4));
q.setS_no(rs.getInt(5));
q.setCorrect_answer(rs.getString(6));
q.setQuiz_id(rs.getString(7));
question.add(q);
}
return question;
}
@Override
public boolean deleteById(Quizz quizz) throws ClassNotFoundException,
SQLException {
boolean deleteUser=false;
try {
Connection connection=connectionManager.openConnection();
PreparedStatement
statement=connection.prepareStatement("DELETE FROM quizz WHERE s_no
= ?");
statement.setInt(1, quizz.getS_no());
int rows=statement.executeUpdate();
if(rows>0) {
deleteUser=true;
}else {
deleteUser=false;
}
}catch(Exception e) {
System.err.println(e);
}
return deleteUser;
@Override
public List<Quizz> getById(Quizz quizz) throws ClassNotFoundException,
SQLException {
List<Quizz> quizList = new ArrayList<>();
Connection connection=connectionManager.openConnection();
PreparedStatement
statemet=connection.prepareStatement("SELECT * FROM quizz WHERE s_no
= ?");
statemet.setInt(1, quizz.getS_no());
ResultSet result=statemet.executeQuery();
while(result.next()) {
Quizz q=new Quizz();
q.setQuiz_id(result.getString("quiz_id"));
q.setS_no(result.getInt("s_no"));
q.setQuestions(result.getString("questions"));
q.setOption1(result.getString("option1"));
q.setOption2(result.getString("option2"));
q.setOption3(result.getString("option3"));
q.setOption4(result.getString("option4"));
q.setCorrect_answer(result.getString("correct_answer"));
q.setWeightage(result.getString("weightage"));
quizList.add(q);
}
return quizList;
}
@Override
public boolean update(Quizz questionlist) throws
ClassNotFoundException, SQLException {
boolean updatequiz=false;
Connection connection=connectionManager.openConnection();
PreparedStatement
statement=connection.prepareStatement("update quizz set
questions=?,option1=?,option2=?,option3=?,option4=?,correct_answer=?,quiz
_id=?,weightage=?");
statement.setString(1, questionlist.getQuestions());
statement.setString(2, questionlist.getOption1());
statement.setString(3, questionlist.getOption2());
statement.setString(4, questionlist.getOption3());
statement.setString(5, questionlist.getOption4());
statement.setString(6, questionlist.getCorrect_answer());
statement.setString(7, questionlist.getQuiz_id());
statement.setString(8, questionlist.getWeightage());
int rows=statement.executeUpdate();
connectionManager.closeConnection();
if(rows>0) {
updatequiz=true;
}else {
updatequiz= false;
}
return updatequiz;
}
package com.demo.DAO;
import java.sql.SQLException;
import java.util.List;
import com.demo.entites.Quizz;
package com.demo.DAO;
import java.sql.SQLException;
import java.util.List;
import com.demo.entites.QuizList;
import com.demo.entites.Quizz;
package com.demo.DAO;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.demo.entites.QuizList;
import com.demo.helper.ConnectionManager;
@Override
public List<QuizList> retrive() throws ClassNotFoundException,
SQLException {
Connection connection=connectionManager.openConnection();
Statement statement=connection.createStatement();
ResultSet result=statement.executeQuery("select * from
quiz_list");
List<QuizList> quizlist=new ArrayList<>();
while(result.next()) {
QuizList quiz=new QuizList();
quiz.setQuiz_id(result.getString(1));
quiz.setS_no(result.getInt(2));
quiz.setQuizes(result.getString(3));
quiz.setCategories(result.getString(4));
quiz.setTotalmarks(result.getInt(5));
quizlist.add(quiz);
}
connectionManager.closeConnection();
return quizlist;
}
@Override
public boolean deleteById(QuizList quiz) throws
ClassNotFoundException, SQLException {
boolean deleteUser=false;
try {
Connection connection=connectionManager.openConnection();
PreparedStatement
statement=connection.prepareStatement("DELETE FROM quiz_list WHERE
quiz_id = ?");
statement.setString(1, quiz.getQuiz_id());
int rows=statement.executeUpdate();
if(rows>0) {
deleteUser=true;
}else {
deleteUser=false;
}
}catch(Exception e) {
System.err.println(e);
}
return deleteUser;
@Override
public List<QuizList> getById(QuizList quiz) throws
ClassNotFoundException, SQLException {
List<QuizList> quizList = new ArrayList<>();
Connection connection=connectionManager.openConnection();
PreparedStatement
statemet=connection.prepareStatement("SELECT * FROM quiz_list WHERE
quiz_id = ?");
statemet.setString(1, quiz.getQuiz_id());
ResultSet result=statemet.executeQuery();
while(result.next()) {
QuizList q=new QuizList();
q.setQuiz_id(result.getString("quiz_id"));
q.setS_no(result.getInt("s_no"));
q.setQuizes(result.getString("quizes"));
q.setCategories(result.getString("catagory"));
q.setTotalmarks(result.getInt("total_marks"));
quizList.add(q);
}
return quizList;
}
@Override
public boolean update(QuizList quizList) throws
ClassNotFoundException, SQLException {
boolean updatequiz=false;
Connection connection=connectionManager.openConnection();
PreparedStatement
statement=connection.prepareStatement("update quiz_list set
quizes=?,catagory=?,total_marks=? where quiz_id=?");
statement.setString(1, quizList.getQuizes());
statement.setString(2, quizList.getCategories());
statement.setInt(3, quizList.getTotalmarks());
statement.setString(4, quizList.getQuiz_id());
int rows=statement.executeUpdate();
connectionManager.closeConnection();
if(rows>0) {
updatequiz=true;
}else {
updatequiz= false;
}
return updatequiz;
package com.demo.DAO;
import java.sql.SQLException;
import com.demo.entites.Users;
package com.demo.DAO;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.demo.entites.Users;
import com.demo.helper.ConnectionManager;
}
package com.demo.entites;
import java.util.Objects;
public QuizList() {}
@Override
public String toString() {
return "QuizList [quiz_id=" + quiz_id + ", s_no=" + s_no + ",
quizes=" + quizes + ", categories=" + catagory
+ ", totalmarks=" + totalmarks + "]";
}
@Override
public int hashCode() {
return Objects.hash(catagory, quiz_id, quizes, s_no, totalmarks);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
QuizList other = (QuizList) obj;
return Objects.equals(catagory, other.catagory) &&
Objects.equals(quiz_id, other.quiz_id)
&& Objects.equals(quizes, other.quizes) && s_no ==
other.s_no && totalmarks == other.totalmarks;
}
package com.demo.entites;
import java.util.Objects;
public Quizz() {}
@Override
public String toString() {
return "Quizz [s_no=" + s_no + ", questions=" + questions + ",
option1=" + option1 + ", option2=" + option2
+ ", option3=" + option3 + ", option4=" + option4 + ",
correct_answer=" + correct_answer + ", quiz_id="
+ quiz_id + ", weightage=" + weightage + "]";
}
@Override
public int hashCode() {
return Objects.hash(correct_answer, option1, option2, option3,
option4, questions, quiz_id, s_no, weightage);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Quizz other = (Quizz) obj;
return Objects.equals(correct_answer, other.correct_answer) &&
Objects.equals(option1, other.option1)
&& Objects.equals(option2, other.option2) &&
Objects.equals(option3, other.option3)
&& Objects.equals(option4, other.option4) &&
Objects.equals(questions, other.questions)
&& Objects.equals(quiz_id, other.quiz_id) && s_no ==
other.s_no
&& Objects.equals(weightage, other.weightage);
}
}
package com.demo.entites;
import java.util.Objects;
public Users() {}
@Override
public String toString() {
return "Users [username=" + username + ", password=" +
password + ", role=" + role + "]";
}
@Override
public int hashCode() {
return Objects.hash(password, role, username);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Users other = (Users) obj;
return Objects.equals(password, other.password) &&
Objects.equals(role, other.role)
&& Objects.equals(username, other.username);
}
package com.demo.exception;
package com.demo.helper;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
connection=DriverManager.getConnection(dataSource.getUrl(),dataSource.get
Username(),dataSource.getPassword());
return connection;
}
package com.demo.helper;
import java.util.ResourceBundle;
}
package com.demo.model;
import java.sql.SQLException;
import java.util.List;
import java.util.Objects;
import com.demo.entites.Quizz;
import com.demo.service.QuestionServiceImpl;
import com.demo.service.Questionsservice;
public QuestionListBean() {}
}
}
package com.demo.model;
import java.util.List;
import com.demo.service.QuizListServiceImpl;
import com.demo.service.QuizListservice;
public QuizListBean() {}
@Override
public String toString() {
return "QuizListBean [quizId=" + quizId + ", serialNo=" + serialNo +
", quizNames=" + quizNames
+ ", quizCategories=" + quizCategories + ",
quizTotalmarks=" + quizTotalmarks + "]";
};
package com.demo.service;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.demo.DAO.QuestionDAOImpl;
import com.demo.DAO.QuestionsDAO;
import com.demo.entites.QuizList;
import com.demo.entites.Quizz;
import com.demo.model.QuestionListBean;
import com.demo.model.QuizListBean;
@Override
public List<QuestionListBean> retrive() throws ClassNotFoundException,
SQLException {
List<QuestionListBean> QuestionBeanList=new ArrayList<>();
try {
List<Quizz> QuestionList=quizDao.retrive();
for(Quizz quiz:QuestionList) {
QuestionListBean QuestionListBean=new
QuestionListBean();
QuestionListBean.setQuizId(quiz.getQuiz_id());
QuestionListBean.setQuestions(quiz.getQuestions());
QuestionListBean.setOption1(quiz.getOption1());
QuestionListBean.setOption2(quiz.getOption2());
QuestionListBean.setOption3(quiz.getOption3());
QuestionListBean.setOption4(quiz.getOption4());
QuestionListBean.setsNo(quiz.getS_no());
QuestionListBean.setCorrectAnswer(quiz.getCorrect_answer());
QuestionBeanList.add(QuestionListBean);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return QuestionBeanList;
}
@Override
public boolean deleteById(Quizz quizz) throws ClassNotFoundException,
SQLException {
return quizDao.deleteById(quizz);
}
@Override
public List<QuestionListBean> getById(Quizz quizz) throws
ClassNotFoundException, SQLException {
List<QuestionListBean> quizBeanList=new ArrayList<>();
try {
List<Quizz> quizList=quizDao.getById(quizz);
for(Quizz quiz1:quizList) {
QuestionListBean QuestionListBean=new
QuestionListBean();
QuestionListBean.setQuizId(quiz1.getQuiz_id());
QuestionListBean.setsNo(quiz1.getS_no());
QuestionListBean.setQuestions(quiz1.getQuestions());
QuestionListBean.setOption1(quiz1.getOption1());
QuestionListBean.setOption2(quiz1.getOption2());
QuestionListBean.setOption3(quiz1.getOption3());
QuestionListBean.setOption4(quiz1.getOption4());
QuestionListBean.setCorrectAnswer(quiz1.getCorrect_answer());
QuestionListBean.setWeightage(quiz1.getWeightage());
quizBeanList.add(QuestionListBean);
}
}catch(ClassNotFoundException e) {
e.printStackTrace();
}catch(SQLException e) {
e.printStackTrace();
}
return quizBeanList;
}
@Override
public boolean update(Quizz questions) throws ClassNotFoundException,
SQLException {
return quizDao.update(questions);
}
package com.demo.service;
import java.sql.SQLException;
import java.util.List;
import com.demo.entites.Quizz;
import com.demo.model.QuestionListBean;
package com.demo.service;
import java.sql.SQLException;
import java.util.List;
import com.demo.entites.QuizList;
import com.demo.model.QuizListBean;
package com.demo.service;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.demo.DAO.QuizDAO;
import com.demo.DAO.QuizDAOImpl;
import com.demo.entites.QuizList;
import com.demo.model.QuizListBean;
quizListBean.setQuizCategories(quiz1.getCategories());
quizListBean.setQuizTotalmarks(quiz1.getTotalmarks());
quizBeanList.add(quizListBean);
}
}catch(ClassNotFoundException e) {
e.printStackTrace();
}catch(SQLException e) {
e.printStackTrace();
}
return quizBeanList;
}
@Override
public boolean update(QuizList quizList) throws
ClassNotFoundException, SQLException {
return quizDAo.update(quizList);
}
}
package com.demo.service;
import java.sql.SQLException;
import com.demo.DAO.UsersDAO;
import com.demo.DAO.UsersDAOImpl;
import com.demo.entites.Users;
import com.demo.exception.AuthenticationException;
package com.demo.service;
import com.demo.entites.Users;
import com.demo.exception.AuthenticationException;
}
///properties
///#connectivity information for mySQL
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/UsersDB
username=root
password=Phani@06
.form-container {
background-color: #fff;
padding: 30px;
border-radius: 10px;
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
width: 400px;
margin-top: 20px;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
label {
font-size: 16px;
color: #333;
margin-top: 10px;
display: block;
}
input[type="text"], select {
width: 100%;
padding: 10px;
margin-top: 5px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 5px;
}
input[type="radio"] {
margin-right: 10px;
}
.options {
margin-bottom: 15px;
}
button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.footer {
text-align: center;
font-size: 12px;
color: #777;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="form-container">
<h1>Create a New Question</h1>
<label>Option 2</label>
<input type="text" name="option2" required>
<label>Option 3</label>
<input type="text" name="option3" required>
<label>Option 4</label>
<input type="text" name="option4" required>
<label>Correct Answer</label>
<input type="text" name="correctAnswer" required>
<label>QuizID</label>
<input type="text" name="quizId" required>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Form</title>
<style>
/* General body styling */
body {
font-family: 'Arial', sans-serif;
background-color: #eaeff1;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
/* Heading style */
.login-container h2 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
/* Label style */
.login-container label {
display: block;
font-size: 14px;
color: #555;
margin-bottom: 6px;
}
.login-container p a {
color: #007bff;
text-decoration: none;
}
.login-container p a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="login-container">
<h2>Login</h2>
<form action="adminlogin" method="post">
<label for="username">Username</label>
<input type="text" id="username" name="username"
placeholder="Enter your username" required>
<label for="password">Password</label>
<input type="password" id="password" name="password"
placeholder="Enter your password" required>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Dashboard Table</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 20px;
}
table {
width: 80%;
margin: 0 auto;
border-collapse: collapse;
background-color: #ffffff;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
}
th, td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #4CAF50;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #ddd;
}
.button {
padding: 6px 12px;
margin: 5px;
font-size: 14px;
color: white;
border: none;
cursor: pointer;
border-radius: 4px;
text-decoration: none;
}
.edit-button {
background-color: #4CAF50;
}
.delete-button {
background-color: #f44336;
}
.edit-button:hover {
background-color: #45a049;
}
.delete-button:hover {
background-color: #e53935;
}
</style>
</head>
<body>
<table cellspacing="2" cellpadding="2" border="2">
<thead>
<tr>
<th>Quiz Id</th>
<th>Quiz Name</th>
<th>Quiz category</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<c:forEach items="${TotalQuizlist}" var="quizlist">
<tr>
<td><c:out value="${quizlist.quizId}"/></td>
<td><c:out value="${f:toUpperCase(quizlist.quizNames)}"/></td>
<td><c:out value="${quizlist.quizCategories}"/></td>
<td>
<!-- Edit and Delete buttons -->
<a href="getbyid?quizId=${quizlist.quizId}" class="button edit-
button">Edit</a>
<a href="deletequiz?quizId=${quizlist.quizId}" class="button
delete-button">Delete</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>
.form-container {
width: 50%;
margin: 0 auto;
padding: 20px;
background-color: #ffffff;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type="text"], select {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
.button {
display: inline-block;
padding: 10px 20px;
margin-top: 20px;
font-size: 16px;
color: white;
border: none;
cursor: pointer;
border-radius: 4px;
text-decoration: none;
background-color: #4CAF50;
}
.button:hover {
background-color: #45a049;
}
.cancel-button {
background-color: #f44336;
margin-left: 10px;
}
.cancel-button:hover {
background-color: #e53935;
}
</style>
</head>
<body>
<div class="form-container">
<h2>Edit Quiz</h2>
<!-- Accessing the first element of TotalQuizlist -->
<c:forEach items="${TotalQuizlist}" var="quiz" varStatus="status"
begin="0" end="0">
<form action="updatequiz" method="post">
<!-- Quiz ID (read-only) -->
<div class="form-group">
<label for="quizId">Quiz ID</label>
<input type="text" id="quizId" name="quizId" value="$
{quiz.quizId}" readonly>
</div>
<div class="form-group">
<label for="quizTotalmarks">Quiz total</label>
<input type="text" id="quizTotalmarks" name="quizTotalmarks"
value="${quiz.quizTotalmarks}" required>
</div>
<!-- Submit and Cancel buttons -->
<button type="submit" class="button">Update</button>
<a href="dashboard.jsp" class="button cancel-button">Cancel</a>
</form>
</c:forEach>
</div>
</body>
</html>
</body>
</html>
<!DOCTYPE html>
<html lang="en" method="post">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
}
.sidebar {
width: 200px;
background-color: #333;
height: 100vh;
color: white;
padding-top: 20px;
position: fixed;
transition: width 0.3s ease;
}
.sidebar a {
text-decoration: none;
color: white;
padding: 10px 15px;
display: block;
}
.sidebar a:hover {
background-color: #575757;
}
.sidebar .submenu {
display: none;
margin-left: 20px;
}
.sidebar .submenu a {
padding-left: 30px;
}
.content {
margin-left: 220px;
padding: 20px;
width: 100%;
}
h1 {
text-align: center;
}
.dashboard-links {
margin-top: 20px;
}
.dashboard-links a {
display: block;
margin: 10px 0;
}
</style>
</head>
<body>
<script>
// Toggle the visibility of the submenu
function toggleSubmenu(id) {
var submenu = document.getElementById(id);
if (submenu.style.display === "block") {
submenu.style.display = "none";
} else {
submenu.style.display = "block";
}
}
// Function to load content dynamically into the content div (optional)
function loadContent(page) {
// Define the URL based on the page clicked
const url = "http://localhost:8085/Onine-Quiz-app/" + page;
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Dashboard Table</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 20px;
}
table {
width: 80%;
margin: 0 auto;
border-collapse: collapse;
background-color: #ffffff;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
}
th, td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #4CAF50;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #ddd;
}
.button {
padding: 6px 12px;
margin: 5px;
font-size: 14px;
color: white;
border: none;
cursor: pointer;
border-radius: 4px;
text-decoration: none;
}
.edit-button {
background-color: #4CAF50;
}
.delete-button {
background-color: #f44336;
}
.edit-button:hover {
background-color: #45a049;
}
.delete-button:hover {
background-color: #e53935;
}
</style>
</head>
<body>
<table cellspacing="2" cellpadding="2" border="2">
<thead>
<tr>
<th>S No</th>
<th>Question</th>
<th>Option-1</th>
<th>Option-2</th>
<th>Option-3</th>
<th>Option-4</th>
<th>Correct Answer</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<c:forEach items="${TotalQuizlist}" var="quizlist">
<tr>
<td><c:out value="${quizlist.sNo}"/></td>
<td><c:out value="${quizlist.Questions}"/></td>
<td><c:out value="${quizlist.Option1}"/></td>
<td><c:out value="${quizlist.Option2}"/></td>
<td><c:out value="${quizlist.Option3}"/></td>
<td><c:out value="${quizlist.Option4}"/></td>
<td><c:out value="${quizlist.CorrectAnswer}"/></td>
<td>
<!-- Edit and Delete buttons -->
<a href="deletebyid?quizId=${quizlist.quizId}" class="button edit-
button">Edit</a>
<a href="deletequestion?quizId=${quizlist.quizId}" class="button
delete-button">Delete</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>
/* Body styling */
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
/* Container styling */
.container {
width: 80%;
margin: 20px;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1);
}
/* Heading styling */
h1 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
/* Table styling */
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 10px;
text-align: left;
border: 1px solid #ddd;
}
th {
background-color: #f9f9f9;
td {
background-color: #f9f9f9;
color: black;
}
/* Button styling */
.btn-start {
padding: 8px 15px;
background-color: red;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
text-align: center;
}
.btn-start:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="container">
<h1>Quiz List</h1>
<table>
<thead>
<tr>
<th>Sr No</th>
<th>Quiz Title</th>
<th>Category</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<c:forEach items="${TotalQuizlist}" var="quizlist">
<tr>
<td><c:out value="${quizlist.serialNo}"/></td>
<td><c:out value="${f:toUpperCase(quizlist.quizNames)}"/></td>
<td><c:out value="${quizlist.quizCategories}"/></td>
<td>
<!-- Edit and Delete buttons -->
<a href="startquiz?quizId=${quizlist.quizId}" class="btn-
start">Start</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<script>
// JavaScript function to handle the "Start" button click
function startQuiz(quizId) {
alert('Starting quiz ' + quizId);
// You can replace this with redirection to the quiz page or logic to load the
quiz
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Form</title>
<style>
/* Basic reset */
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Body styling */
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
/* Login container */
.login-container {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}
/* Heading styling */
h2 {
margin-bottom: 20px;
font-size: 24px;
color: #333;
}
.textbox input {
width: 100%;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
outline: none;
}
/* Button styling */
.btn {
width: 100%;
padding: 10px;
font-size: 18px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.btn:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="login-container">
<div class="login-box">
<div class="user-icon">
<img src="avatar.png" alt="User Icon">
</div>
<h2>Login</h2>
<form action="userlogin" method="post">
<div class="textbox">
<input type="text" name="username" placeholder="Username"
required>
</div>
<div class="textbox">
<input type="password" name="password" placeholder="Password"
required>
</div>
<button type="submit" class="btn">Login</button>
</form>
</div>
</div>
</body>
</html>