package com.otts.servlet;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import com.otts.dao.GetStudentCountDAO;
import com.otts.dao.GetStudentIDDAO;
import com.otts.dao.GetTeacherIDDAO;
import com.otts.dao.GetTestIDDAO;
import com.otts.service.AssignQuestiontoTestService;
import com.otts.service.AssignStudentService;
import com.otts.service.CreateQuestionService;
import com.otts.service.CreateTestService;
import com.otts.service.DeleteQuestionService;
import com.otts.service.DeleteQuestionfromTestService;
import com.otts.service.DeleteStudentService;
import com.otts.service.DeleteTestService;
import com.otts.service.TakeTestService;
import com.otts.service.UpdateQntoTestService;
import com.otts.service.UpdateQuestionService;
import com.otts.service.UpdateStudentService;
import com.otts.service.UpdateTestService;
import com.otts.service.ViewQnfromTest1Service;
import com.otts.service.ViewQnfromTestService;
import com.otts.service.ViewQues1Service;
import com.otts.service.ViewQuestionService;
import com.otts.service.ViewStudentService;
import com.otts.service.ViewTestService;
import com.otts.vo.CreateTestVo;
import com.otts.vo.DeleteTestVo;
import com.otts.vo.QuestionVO;
import com.otts.vo.StudentVO;
import com.otts.vo.TakeTestVO;
import com.otts.vo.TestVO;
import com.otts.vo.TestVO1;
import com.otts.vo.ViewTestVo;
/**
* Servlet implementation class TestQuestionManagementServlet
*/
public class TestQuestionManagementServlet extends HttpServlet {
private static final Logger log = Logger
.getLogger(TestQuestionManagementServlet.class);
private static final long serialVersionUID = 1L;
public int selectedAnsArray[] = new int[10];
String testName, category;
int duration, participants, invigilator, testID;
CreateTestVo createtestvo = new CreateTestVo();
CreateTestService createtestservice = new CreateTestService();
ViewTestVo viewtest = new ViewTestVo();
/**
* @see HttpServlet#HttpServlet()
*/
public TestQuestionManagementServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#service(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// Servlet for CreateQuestion
String pagename = request.getParameter("pagename");
log.info("Page : " + pagename);
if (pagename.equals("CreateQuestion")) {
int teacherid = Integer.parseInt(request.getParameter("teacherid"));
int questionid = Integer.parseInt(request
.getParameter("questionid"));
String questioncontent = request.getParameter("questioncontent");
String category = request.getParameter("category");
String option1 = request.getParameter("option1");
String option2 = request.getParameter("option2");
String option3 = request.getParameter("option3");
String option4 = request.getParameter("option4");
int correctanswer = Integer.parseInt(request
.getParameter("correctanswer"));
GetTeacherIDDAO teaid = new GetTeacherIDDAO();
int teacheridcheck = 0;
teacheridcheck = teaid.getTeacherId(teacherid);
if (teacheridcheck == 0) {
String status = "Teacher Id not present";
log.info("Teacher Id not present in Servlet");
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/ FailureCaseinDatabase.jsp");
request.setAttribute("status", status);
rd1.forward(request, response);
} else {
// setting values to vo
log.info(questioncontent + "content servlet");
QuestionVO question = new QuestionVO();
question.setTeacherid(teacherid);
question.setCategory(category);
question.setQuestionid(questionid);
question.setQuestioncontent(questioncontent);
log.info(questioncontent);
question.setOption1(option1);
question.setOption2(option2);
question.setOption3(option3);
question.setOption4(option4);
question.setCorrectanswer(correctanswer);
CreateQuestionService createques = new CreateQuestionService();
int count = 0;
try {
count = createques.insertQuestion(question, 1);
} catch (Exception e) {
// TODO Auto-generated catch block
log.info("Failed at Servlet");
log.info("Failed at servlet Create Question");
}
// Success Page
if (count >= 1) {
request.setAttribute("mycount", count);
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher(
"/JSP/InsertQuestionSucess.jsp");
log.info("Question Inserted");
rd1.forward(request, response);
// Error Page
} else {
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/FailureCase.jsp");
log.info("Failed to insert question");
rd1.forward(request, response);
}
}
// Servlet for AssignQuestion
} else if (pagename.equalsIgnoreCase("assignQuestion")) {
int questionId1 = Integer.parseInt(request
.getParameter("questionId1"));
int questionId2 = Integer.parseInt(request
.getParameter("questionId2"));
int questionId3 = Integer.parseInt(request
.getParameter("questionId3"));
int questionId4 = Integer.parseInt(request
.getParameter("questionId4"));
int questionId5 = Integer.parseInt(request
.getParameter("questionId5"));
int questionId6 = Integer.parseInt(request
.getParameter("questionId6"));
int questionId7 = Integer.parseInt(request
.getParameter("questionId7"));
int questionId8 = Integer.parseInt(request
.getParameter("questionId8"));
int questionId9 = Integer.parseInt(request
.getParameter("questionId9"));
int questionId10 = Integer.parseInt(request
.getParameter("questionId10"));
int testId = Integer.parseInt(request.getParameter("testId"));
// Create object for Testvo
TestVO question = new TestVO();
question.setQuestionId1(questionId1);
question.setQuestionId2(questionId2);
question.setQuestionId3(questionId3);
question.setQuestionId4(questionId4);
question.setQuestionId5(questionId5);
question.setQuestionId6(questionId6);
question.setQuestionId7(questionId7);
question.setQuestionId8(questionId8);
question.setQuestionId9(questionId9);
question.setQuestionId10(questionId10);
question.setTestId(testId);
question.setTestId(testId);
AssignQuestiontoTestService assignquestionservice = new AssignQuestiontoTestService();
int count = 0;
try {
count = assignquestionservice.data(question);
} catch (Exception e) {
e.printStackTrace();
}
// Success Page
if (count >= 1) {
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/ViewAssignQnSuccess.jsp");
rd1.forward(request, response);
// ErrorPage
} else if (count == -2) {
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/ViewAssignQnFailure.jsp");
rd1.forward(request, response);
}
}
// Srevlet for Update QuestionId
else if (pagename.equalsIgnoreCase("Update3")) {
int testid = Integer.parseInt(request.getParameter("testid"));
int question1 = Integer.parseInt(request
.getParameter("questionid1"));
int question2 = Integer.parseInt(request
.getParameter("questionid2"));
int question3 = Integer.parseInt(request
.getParameter("questionid3"));
int question4 = Integer.parseInt(request
.getParameter("questionid4"));
int question5 = Integer.parseInt(request
.getParameter("questionid5"));
int question6 = Integer.parseInt(request
.getParameter("questionid6"));
int question7 = Integer.parseInt(request
.getParameter("questionid7"));
int question8 = Integer.parseInt(request
.getParameter("questionid8"));
int question9 = Integer.parseInt(request
.getParameter("questionid9"));
int question10 = Integer.parseInt(request
.getParameter("questionid10"));
TestVO question = new TestVO();
question.setTestId(testid);
question.setQuestionId1(question1);
question.setQuestionId2(question2);
question.setQuestionId3(question3);
question.setQuestionId4(question4);
question.setQuestionId5(question5);
question.setQuestionId6(question6);
question.setQuestionId7(question7);
question.setQuestionId8(question8);
question.setQuestionId9(question9);
question.setQuestionId10(question10);
UpdateQntoTestService upques = new UpdateQntoTestService();
int count = upques.updateQuestion(question);
// Success Page
if (count >= 1) {
request.setAttribute("mycount", count);
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/UpdateQntoTestSuccess.jsp");
rd1.forward(request, response);
// ErrorPage
} else {
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/UpdateQntoTestFailure.jsp");
rd1.forward(request, response);
}
}
// Servlet for UpdateTest
else if (pagename.equalsIgnoreCase("update1")) {
int testId = Integer.parseInt(request.getParameter("testId"));
ViewQnfromTest1Service vqs = new ViewQnfromTest1Service();
HashMap<Integer, TestVO> ar = null;
try {
ar = vqs.viewQuestions(testId);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
log.info(ar);
System.out.println("ajs");
request.setAttribute("arr", ar);
RequestDispatcher rd1 = getServletContext().getRequestDispatcher(
"/JSP/UpdateQuestiontoTestDB.jsp");
rd1.forward(request, response);
}
// Servlet for UpdateQuestion
else if (pagename.equals("update2")) {
log.info(pagename);
RequestDispatcher rd1 = getServletContext().getRequestDispatcher(
"/JSP/UpdateQuestiontoTestFinal.jsp");
String test1 = request.getParameter("testId1");
String qn1 = request.getParameter("questionId1");
String qn2 = request.getParameter("questionId2");
String qn3 = request.getParameter("questionId3");
String qn4 = request.getParameter("questionId4");
String qn5 = request.getParameter("questionId5");
String qn6 = request.getParameter("questionId6");
String qn7 = request.getParameter("questionId7");
String qn8 = request.getParameter("questionId8");
String qn9 = request.getParameter("questionId9");
String qn10 = request.getParameter("questionId10");
request.setAttribute("testId1", test1);
request.setAttribute("qid1", qn1);
request.setAttribute("qid2", qn2);
request.setAttribute("qid3", qn3);
request.setAttribute("qid4", qn4);
request.setAttribute("qid5", qn5);
request.setAttribute("qid6", qn6);
request.setAttribute("qid7", qn7);
request.setAttribute("qid8", qn8);
request.setAttribute("qid9", qn9);
request.setAttribute("qid10", qn10);
try {
rd1.forward(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// Servlet for DeleteQuestion
else if (pagename.equalsIgnoreCase("deleteQuestion")) {
int count = 0;
int testId = Integer.parseInt(request.getParameter("testId"));
TestVO question = new TestVO();
question.setTestId(testId);
DeleteQuestionfromTestService deletequestiontservice = new DeleteQuestionfromTestService();
try {
count = deletequestiontservice.data(question);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (count >= 1) {
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/DeleteAssignQnSuccess.jsp");
try {
rd1.forward(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
log.info("error");
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/DeleteAssignQnFailure.jsp");
rd1.forward(request, response);
}
}
// Servlet for View Question
else if (pagename.equals("viewQuestion11")) {
List count;
int testId = Integer.parseInt(request.getParameter("testId"));
TestVO quest = new TestVO();
quest.setTestId(testId);
GetTestIDDAO tesid = new GetTestIDDAO();
int testidcheck = tesid.getTestId(testId);
ViewQnfromTestService obj = new ViewQnfromTestService();
count = obj.calculate(testId);
if (testidcheck == 0) {
String status = "Test Id not present";
log.info("Test Id not present in Servlet");
request.setAttribute("status", status);
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/ FailureCaseinDatabase.jsp");
rd1.forward(request, response);
}
else if (count != null) {
RequestDispatcher rd = getServletContext()
.getRequestDispatcher(
"/JSP/ViewQuestiontoTestSuccess.jsp");
request.setAttribute("UpdateDetails", count);
rd.forward(request, response);
} else {
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher(
"/JSP/ViewQuestiontoTestFailure.jsp");
rd1.forward(request, response);
}
}
// Servlet for UpdateQuestion
else if (pagename.equals("UpdateQuestion")) {
int questionid = Integer.parseInt(request
.getParameter("questionid"));
String questioncontent = request.getParameter("questioncontent");
String category = request.getParameter("category");
String option1 = request.getParameter("option1");
String option2 = request.getParameter("option2");
String option3 = request.getParameter("option3");
String option4 = request.getParameter("option4");
int correctanswer = Integer.parseInt(request
.getParameter("correctanswer"));
QuestionVO question = new QuestionVO();
question.setCategory(category);
question.setQuestionid(questionid);
question.setQuestioncontent(questioncontent);
question.setOption1(option1);
question.setOption2(option2);
question.setOption3(option3);
question.setOption4(option4);
question.setCorrectanswer(correctanswer);
UpdateQuestionService upques = new UpdateQuestionService();
int count = upques.updateQuestion(question);
if (count >= 1) {
request.setAttribute("mycount", count);
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/UpdateQuestionSucess.jsp");
log.info("Question Updated Successfully");
rd1.forward(request, response);
} else {
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/FailureCase.jsp");
log.info("Question does not Updated");
rd1.forward(request, response);
}
// Servlet for ViewQuestion By category
} else if (pagename.equals("ViewQuestion")) {
String category = request.getParameter("category");
ViewQuestionService vqs = new ViewQuestionService();
HashMap<Integer, QuestionVO> ar = vqs.viewQuestions(category);
log.info(ar);
request.setAttribute("arr", ar);
RequestDispatcher rd1 = getServletContext().getRequestDispatcher(
"/JSP/ViewQuestionsSucess.jsp");
log.info("Question Viewed Successfully");
rd1.forward(request, response);
} else if (pagename.equals("ViewQuestionsCategory")) {
String category = request.getParameter("category");
ViewQuestionService vqs = new ViewQuestionService();
HashMap<Integer, QuestionVO> arr = vqs.viewQuestions(category);
log.info(arr);
request.setAttribute("arr", arr);
RequestDispatcher rd1 = getServletContext().getRequestDispatcher(
"/JSP/ViewQuestionsOnly.jsp");
log.info("Question Viewed by catagory");
rd1.forward(request, response);
// Servlet for DeleteQuestion
} else if (pagename.equals("DeleteQuestion")) {
int questionid = Integer.parseInt(request
.getParameter("questionid"));
DeleteQuestionService dqs = new DeleteQuestionService();
int count = dqs.deleteQuestion(questionid);
if (count >= 1) {
request.setAttribute("mycount", count);
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/DeleteQuestionSucess.jsp");
log.info("Question Deleteded Successfully");
rd1.forward(request, response);
} else {
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/FailureCase.jsp");
log.info("Question failed to delete");
rd1.forward(request, response);
}
} else if (pagename.equals("viewquestionsuccess")) {
RequestDispatcher rd1 = getServletContext().getRequestDispatcher(
"/JSP/UpdateQuestion.jsp");
log.info("Question Viewed Successfully");
String quesid = request.getParameter("qid");
String quescategory = request.getParameter("category");
String quescontent = request.getParameter("questioncontent");
String option1 = request.getParameter("option1");
String option2 = request.getParameter("option2");
String option3 = request.getParameter("option3");
String option4 = request.getParameter("option4");
String correctanswer = request.getParameter("correctanswer");
log.info(quesid);
request.setAttribute("qid", quesid);
request.setAttribute("qcnt", quescontent);
request.setAttribute("option1", option1);
request.setAttribute("option2", option2);
request.setAttribute("option3", option3);
request.setAttribute("option4", option4);
request.setAttribute("correctanswer", correctanswer);
request.setAttribute("category", quescategory);
try {
rd1.forward(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// Servlet for AssignStudent
else if (pagename.equals("AssignStudent")) {
int testId = Integer.parseInt(request.getParameter("testId"));
int studentId = Integer.parseInt(request.getParameter("studentId"));
int teacherId = Integer.parseInt(request.getParameter("teacherId"));
int stuidcheck = 0;
int testidcheck = 0;
int teacheridcheck = 0;
String status;
GetStudentIDDAO stuid = new GetStudentIDDAO();
stuidcheck = stuid.getStudentId(studentId);
GetTestIDDAO tesid = new GetTestIDDAO();
testidcheck = tesid.getTestId(testId);
GetTeacherIDDAO teaid = new GetTeacherIDDAO();
teacheridcheck = teaid.getTeacherId(teacherId);
GetStudentCountDAO stucnt = new GetStudentCountDAO();
int checkstu = stucnt.checkStudentCount(testId);
if (checkstu == 0) {
status = "Student Count Excedded Maximum Allocated Students.";
log
.info("Student Count Excedded Maximum Allocated Students in Servlet");
request.setAttribute("status", status);
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/ FailureCaseinDatabase.jsp");
rd1.forward(request, response);
} else if (testidcheck == 0) {
status = "Test Id not present";
log.info("Test Id not present in Servlet");
request.setAttribute("status", status);
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/ FailureCaseinDatabase.jsp");
rd1.forward(request, response);
} else if (stuidcheck == 0) {
status = "Student Id not present";
log.info("Student Id not present in Servlet");
request.setAttribute("status", status);
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/ FailureCaseinDatabase.jsp");
rd1.forward(request, response);
} else if (teacheridcheck == 0) {
status = "Teacher Id not present";
log.info("Teacher Id not present in Servlet");
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/ FailureCaseinDatabase.jsp");
request.setAttribute("status", status);
rd1.forward(request, response);
} else {
StudentVO student = new StudentVO();
student.setStudentId(studentId);
student.setTestId(testId);
student.setTeacherId(teacherId);
AssignStudentService assignstudentservice = new AssignStudentService();
int count = 0;
try {
count = assignstudentservice.data(student);
} catch (Exception e) {
e.printStackTrace();
}
if (count >= 1) {
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher(
"/JSP/AssignStudentSuccess.jsp");
rd1.forward(request, response);
}
}
// servlet for ViewStudent
} else if (pagename.equals("ViewStudent")) {
int testId = Integer.parseInt(request.getParameter("testId"));
StudentVO student = new StudentVO();
student.setTestId(testId);
ViewStudentService viewstudentservice = new ViewStudentService();
ArrayList Ar = new ArrayList();
try {
Ar = viewstudentservice.viewStudent(testId);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setAttribute("arr", Ar);
RequestDispatcher rd1 = getServletContext().getRequestDispatcher(
"/JSP/ViewStudentSuccess.jsp");
rd1.forward(request, response);
// Servlet for UpdateStudent
} else if (pagename.equals("UpdateStudent")) {
int studentId = Integer.parseInt(request.getParameter("studentId"));
int testId = Integer.parseInt(request.getParameter("testId"));
int teacherId = Integer.parseInt(request.getParameter("teacherId"));
int stuidcheck = 0;
int testidcheck = 0;
int teacheridcheck = 0;
String status;
GetStudentIDDAO stuid = new GetStudentIDDAO();
stuidcheck = stuid.getStudentId(studentId);
GetTestIDDAO tesid = new GetTestIDDAO();
testidcheck = tesid.getTestId(testId);
GetTeacherIDDAO teaid = new GetTeacherIDDAO();
teacheridcheck = teaid.getTeacherId(teacherId);
if (testidcheck == 0) {
status = "Test Id not present";
log.info("Test Id not present in Servlet");
request.setAttribute("status", status);
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/ FailureCaseinDatabase.jsp");
rd1.forward(request, response);
} else if (stuidcheck == 0) {
status = "Student Id not present";
log.info("Student Id not present in Servlet");
request.setAttribute("status", status);
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/ FailureCaseinDatabase.jsp");
rd1.forward(request, response);
} else if (teacheridcheck == 0) {
status = "Teacher Id not present";
log.info("Teacher Id not present in Servlet");
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/ FailureCaseinDatabase.jsp");
request.setAttribute("status", status);
rd1.forward(request, response);
} else {
StudentVO student = new StudentVO();
student.setStudentId(studentId);
student.setTestId(testId);
student.setTeacherId(teacherId);
UpdateStudentService updatestudentservice = new UpdateStudentService();
int count = 0;
try {
count = updatestudentservice.data(student);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (count >= 1) {
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher(
"/JSP/UpdateStudentSuccess.jsp");
rd1.forward(request, response);
}
}
// Servlet for DeleteStudent
} else if (pagename.equals("DeleteStudent")) {
int count = 0;
int studentId = Integer.parseInt(request.getParameter("studentId"));
StudentVO student = new StudentVO();
student.setStudentId(studentId);
DeleteStudentService deletestudentservice = new DeleteStudentService();
try {
count = deletestudentservice.data(student);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (count >= 1) {
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/DeleteStudentSuccess.jsp");
try {
rd1.forward(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
log.info("error");
}
// Servlet for CreateTest
} else if (pagename.equals("CreateTest")) {
testName = request.getParameter("testName");
testID = Integer.parseInt(request.getParameter("testID"));
duration = Integer.parseInt(request.getParameter("duration"));
participants = Integer.parseInt(request
.getParameter("participants"));
invigilator = Integer.parseInt(request.getParameter("invigilator"));
category = request.getParameter("category");
createtestvo.setTestName(testName);
createtestvo.setTestID(testID);
createtestvo.setDuration(duration);
createtestvo.setParticipants(participants);
createtestvo.setInvigilator(invigilator);
createtestvo.setCategory(category);
int count = 0;
try {
count = createtestservice.data(createtestvo);
} catch (SQLException e) {
e.printStackTrace();
}
if (count >= 1) {
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/CreateTestSuccess.jsp");
request.setAttribute("checks", "1");
rd1.forward(request, response);
}
}// Servlet for UpdateTest
else if (pagename.equalsIgnoreCase("UpdateTest3")) {
int testid = Integer.parseInt(request.getParameter("testid"));
String testName = request.getParameter("testName");
int duration = Integer.parseInt(request.getParameter("duration"));
String category = request.getParameter("category");
int count1 = Integer.parseInt(request.getParameter("count"));
int invigilator = Integer.parseInt(request
.getParameter("invigilator"));
TestVO1 question = new TestVO1();
question.setTestID(testid);
question.setTestName(testName);
question.setDuration(duration);
question.setCategory(category);
question.setNoofstudent(count1);
question.setInvigilatorID(invigilator);
UpdateTestService upques = new UpdateTestService();
int count = upques.updateQuestion(question);
if (count >= 1) {
request.setAttribute("mycount", count);
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/UpdateTestSuccess.jsp");
rd1.forward(request, response);
} else {
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/UpdateTestFailure.jsp");
rd1.forward(request, response);
}
}
else if (pagename.equalsIgnoreCase("updateTest1")) {
int testId = Integer.parseInt(request.getParameter("testId"));
ViewQues1Service vqs = new ViewQues1Service();
HashMap<Integer, TestVO1> ar = vqs.viewQuestions(testId);
request.setAttribute("arr", ar);
RequestDispatcher rd1 = getServletContext().getRequestDispatcher(
"/JSP/UpdateTestDB1.jsp");
rd1.forward(request, response);
}
else if (pagename.equalsIgnoreCase("updateTest2")) {
log.info(pagename);
RequestDispatcher rd1 = getServletContext().getRequestDispatcher(
"/JSP/UpdateTestFinal.jsp");
String test1 = request.getParameter("testId1");
String testName1 = request.getParameter("testName");
String duration1 = request.getParameter("duration");
String category1 = request.getParameter("category");
String count1 = request.getParameter("noofStudents");
String invigilator1 = request.getParameter("invigilatorId");
request.setAttribute("testId2", test1);
request.setAttribute("testName2", testName1);
request.setAttribute("duration2", duration1);
request.setAttribute("category2", category1);
request.setAttribute("count2", count1);
request.setAttribute("invigilator2", invigilator1);
try {
rd1.forward(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Servlet for DeleteTest
} else if (pagename.equals("DeleteTest")) {
int testID;
DeleteTestVo deletetestvo = new DeleteTestVo();
DeleteTestService deletetestservice = new DeleteTestService();
testID = Integer.parseInt(request.getParameter("testID"));
deletetestvo.setTestID(testID);
int count = 0;
try {
count = deletetestservice.test(deletetestvo);
} catch (SQLException e) {
e.printStackTrace();
}
if (count >= 1) {
RequestDispatcher rd1 = getServletContext()
.getRequestDispatcher("/JSP/DeleteTestSuccess.jsp");
request.setAttribute("checks", "2");
rd1.forward(request, response);
}
} else if (pagename.equals("ViewTest")) {
List ls = new ArrayList();
ViewTestVo viewtest = new ViewTestVo();
ViewTestService viewtestservice = new ViewTestService();
ls = (List) viewtestservice.calculate(viewtest);
if (ls != null) {
RequestDispatcher rd = getServletContext()
.getRequestDispatcher("/JSP/ViewTestSucess.jsp");
request.setAttribute("ViewTestDetails", ls);
rd.forward(request, response);
}
// Servlet for AttendingTest
} else if (pagename.equals("AttendingTest")) {
String submitValue = request.getParameter("submit");
log.info("Submit value : " + submitValue);
if (submitValue.equals("Submit")) {
int testId = Integer.parseInt(request.getParameter("testId"));
log.info("Entered test id: " + testId);
int studentId = Integer.parseInt(request
.getParameter("studentId"));
log.info("Entered student id: " + studentId);
TakeTestService testService = new TakeTestService();
int check = 0;
try {
check = testService.checkValideStudent(studentId, testId);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (check == 0) {
RequestDispatcher rd = getServletContext()
.getRequestDispatcher("/JSP/StartTestFailure.jsp");
log.info("Invalid login");
// request.setAttribute("invalidinput", 1);
rd.forward(request, response);
} else {
log.info("Vaild user!!!");
int qidIndex = 1;
TakeTestVO testVO = new TakeTestVO();
ArrayList<TakeTestVO> ar = null;
testVO.setTestId(testId);
testVO.setQid(qidIndex);
ar = testService.viewTestQnService(testId, qidIndex,
studentId);
log.info("Returned back to servlet");
if (ar != null) {
RequestDispatcher rd = getServletContext()
.getRequestDispatcher("/JSP/TakeTest.jsp");
request.setAttribute("qnDetails", ar);
rd.forward(request, response);
}
}
} else if (submitValue.equals("Save")
|| submitValue.equals("Cancel")) {
int selectedAnswer;
int testId = Integer.parseInt(request.getParameter("testId"));
log.info("Entered test id: " + testId);
int qnId = Integer.parseInt(request.getParameter("questionId"));
log.info("QuestionId to save/cancel : " + qnId);
int index = Integer.parseInt(request.getParameter("index"));
log.info("Index :" + index);
int studentid = Integer.parseInt(request
.getParameter("studentId"));
log.info("studentid :" + studentid);
if (submitValue.equals("Save")) {
selectedAnswer = Integer.parseInt(request
.getParameter("option"));
log.info("Selected option : " + selectedAnswer);
selectedAnsArray[index - 1] = selectedAnswer;
} else {
selectedAnswer = 0;
selectedAnsArray[index - 1] = selectedAnswer;
}
TakeTestService saveService = new TakeTestService();
TakeTestVO testIdVO = new TakeTestVO();
ArrayList<TakeTestVO> ar = null;
testIdVO.setTestId(testId);
testIdVO.setQid(qnId);
testIdVO.setIndex(index);
log.info("Entering service method!!");
selectedAnsArray[index - 1] = selectedAnswer;
ar = saveService.saveAnswerService(testId, qnId,
selectedAnswer, index, studentid);
log.info("Returned back to servlet");
if (ar != null) {
RequestDispatcher rd = getServletContext()
.getRequestDispatcher("/JSP/TakeTest.jsp");
request.setAttribute("qnDetails", ar);
rd.forward(request, response);
} else {
log.info("ArrayList is empty. Nothing to send to jsp file");
}
} else if (submitValue.equals("Save All")) {
int selectedOption;
int testId = Integer.parseInt(request.getParameter("testId"));
log.info("Entered test id: " + testId);
int qnId = Integer.parseInt(request.getParameter("questionId"));
log.info("QuestionId to save/cancel : " + qnId);
String opt = request.getParameter("option");
if (opt == null)
selectedOption = 0;
else
selectedOption = Integer.parseInt(opt);
log.info("Selected option : " + selectedOption);
int index = Integer.parseInt(request.getParameter("index"));
log.info("Index :" + index);
int studentid = Integer.parseInt(request
.getParameter("studentId"));
log.info("studentid :" + studentid);
selectedAnsArray[index - 1] = selectedOption;
TakeTestService saveService = new TakeTestService();
TakeTestVO testIdVO = new TakeTestVO();
testIdVO.setTestId(testId);
testIdVO.setQid(qnId);
testIdVO.setIndex(index);
log.info("Entering service method!!");
int count = saveService.saveAllAnswerService(testId, qnId,
selectedOption, index, studentid, selectedAnsArray);
log.info("Returned back to servlet");
if (count != 0) {
RequestDispatcher rd = getServletContext()
.getRequestDispatcher("/JSP/FinishTest.jsp");
rd.forward(request, response);
} else {
log.info("ArrayList is empty. Nothing to send to jsp file");
}
} else {
int testId = Integer.parseInt(request.getParameter("testId"));
log.info("Entered test id: " + testId);
int studentId = Integer.parseInt(request
.getParameter("studentId"));
log.info("studentid :" + studentId);
int qidIndex = 1;
int index = Integer.parseInt(request.getParameter("index"));
if (submitValue.equals("Prev")) {
index = index - 1;
} else if (submitValue.equals("Next")) {
index = index + 1;
} else {
index = Integer.parseInt(submitValue);
}
qidIndex = index;
log.info("Navigation key entered : " + index);
TakeTestService testService = new TakeTestService();
TakeTestVO testIdVO = new TakeTestVO();
ArrayList<TakeTestVO> ar = null;
testIdVO.setTestId(testId);
testIdVO.setQid(qidIndex);
ar = testService.viewTestQnService(testId, qidIndex, studentId);
log.info("Returned back to servlet");
if (ar != null) {
RequestDispatcher rd = getServletContext()
.getRequestDispatcher("/JSP/TakeTest.jsp");
request.setAttribute("qnDetails", ar);
rd.forward(request, response);
} else {
log.info("ArrayList is empty. Nothing to send to jsp file");
}
}
} else {
RequestDispatcher rd = getServletContext().getRequestDispatcher(
"/JSP/FailureCase.jsp");
rd.forward(request, response);
}
}
}