How to check the answer is correct or not? : I am creating an Online Examination System . I managed to show the questions and take the answer but i am having trouble to check the  answer is correct or not. My approach is if the answer is correct then its add-mark by 1 and return the marks to the **result.jsp** page .I post the codes at below. 
Please give me some solutions.  Thank you..

**view.jsp ( In this page the answers are takes and passes the answer for Checking   )**

    <div  class="col-sm-8" > 
       <form method="post" action="Resultprocess"> 
      <% int i=1; %>
      <c:forEach items="${examq}" var="examq" >
      
      <label style="color:red">Q<c:out value="${examq.getQid()}"></c:out>:- <c:out value="${examq.getQuestion()}"></c:out></label><br>
      
      <label style="color:white" >O1:<c:out value="${examq.getOption1()}"></c:out></label>
      <input type="radio" name="option<%=i %>" value="<c:out value="${examq.getOption1()}"></c:out>" /><br>
      
      <label style="color:white" >O2:<c:out value="${examq.getOption2()}"></c:out></label>
      <input type="radio" name="option<%=i %>"  value="<c:out value="${examq.getOption2()}"></c:out>"/><br>
      
      <label style="color:white" >O3:<c:out value="${examq.getOption3()}"></c:out></label>
      <input type="radio" name="option<%=i %>" value ="<c:out value ="${examq.getOption3()}"></c:out>"/><br>
      
      <label style="color:white" >O4:<c:out value="${examq.getOption4() }"></c:out></label>
      <input type="radio" name="option<%=i %>" value ="<c:out value="${examq.getOption4()}"></c:out>"/><br>  
       
      <hr>   
      <%i++; %>      
        </c:forEach> 
       
      
        <input type="submit" value="submit">
         
     </form>
    
      <a href="takeexam.jsp">GoBack</a>
      
      </div>
**Resultprocess.java**

    package exam.controller;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    
    
    
    import exam.DAO.CTest;
    import exam.DTO.ExamQ;
    
    @WebServlet("/Resultprocess")
    public class Resultprocess extends HttpServlet {
    	private static final long serialVersionUID = 1L;
    
    	
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		
             for(int i=1;i<=6;i++) {
    		String ans =request.getParameter("option"+i);
    		HttpSession session = request.getSession();
    		session .setAttribute("answer", ans);
    	     System.out.println(ans);
    			
    			ExamQ answer1 = new ExamQ();
    			answer1.setAnswer(ans);
    			
    			CTest cans =new CTest();
    			boolean ansercheck = cans.getans(answer1);
    			if(ansercheck == true) {
    				
    				HttpSession session1 = request.getSession();
    				session1.setAttribute("answer1", answer1);
    				session1.setAttribute("answercheck",String.valueOf(ans));
    				RequestDispatcher rd =request.getRequestDispatcher("result.jsp");
    				rd.forward(request, response);	
    			}	
    		}
    		}
          }

**CTest.java**

    package exam.DAO;
    import java.sql.*;
    import java.util.ArrayList;
    
    
    
    
    import exam.DTO.ExamQ;
    import exam.utilities.ConnectionFac;
    
    public class CTest {
    	
    	Connection cn = null;
    	PreparedStatement ps = null;
    	Statement st = null;
    	ResultSet rs = null;
    	ConnectionFac con = new ConnectionFac();
    	String selectctest ="select * from ctest";
    	
    	
    	public ArrayList<ExamQ> getdata() {
    		
    		ArrayList<ExamQ> arr =new ArrayList<ExamQ>();
    		
    		
    		try {
    			rs=con.getResultSet(selectctest);
    			while(rs.next()) {
    				ExamQ examques =new ExamQ();
    				examques.setQid(rs.getInt(1));
    				examques.setQuestion(rs.getString(2));
    				examques.setOption1(rs.getString(3));
    				examques.setOption2(rs.getString(4));
    				examques.setOption3(rs.getString(5));
    				examques.setOption4(rs.getString(6));
    				examques.setAnswer(rs.getString(7));
    				arr.add(examques);
    				
    			}
    		} catch (SQLException e) {
    			
    			e.printStackTrace();
    		}
    		return arr;
    	}
    	
    
    	
    	public boolean getans( ExamQ answer) {
    		
    		
    			try {
    				rs = con.getResultSet(selectctest);
    				while(rs.next()) {
    					String quesDB =rs.getString(2);
    					String answerDB = rs.getString(7);
    					
    					ExamQ  examdb = new ExamQ();
    					examdb.setQid(rs.getInt(1));
    					examdb.setQuestion(quesDB);
    					examdb.setAnswer(answerDB);
    					
    					if(answer.equals(examdb)) {
    						return true;
    						
    					}
    				}
    				
    			} catch (SQLException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    			return false;	
    	}
    }

**ExamQ.java**

    package exam.DTO;
    
    public class ExamQ {
    	int qid;
    	String question;
    	String option1;
    	String option2;
    	String option3;
    	String option4;
    	String answer;
    	
    	public int getQid() {
    		return qid;
    	}
    	public void setQid(int qid) {
    		this.qid = qid;
    	}
    	public String getQuestion() {
    		return question;
    	}
    	public void setQuestion(String question) {
    		this.question = question;
    	}
    	public String getOption1() {
    		return option1;
    	}
    	public void setOption1(String option1) {
    		this.option1 = option1;
    	}
    	public String getOption2() {
    		return option2;
    	}
    	public void setOption2(String option2) {
    		this.option2 = option2;
    	}
    	public String getOption3() {
    		return option3;
    	}
    	public void setOption3(String option3) {
    		this.option3 = option3;
    	}
    	public String getOption4() {
    		return option4;
    	}
    	public void setOption4(String option4) {
    		this.option4 = option4;
    	}
    	public String getAnswer() {
    		return answer;
    	}
    	public void setAnswer(String answer) {
    		this.answer = answer;
    	}
    	
    	@Override
    	public boolean equals(Object obj) {
    		if (this == obj)
    			return true;
    		if (obj == null)
    			return false;
    		if (!(obj instanceof ExamQ))
    			return false;
    		ExamQ other = (ExamQ) obj;
    		if (answer == null) {
    			if (other.answer != null)
    				return false;
    		} else if (!answer.equals(other.answer))
    			return false;
    		if (option1 == null) {
    			if (other.option1 != null)
    				return false;
    		} else if (!option1.equals(other.option1))
    			return false;
    		if (option2 == null) {
    			if (other.option2 != null)
    				return false;
    		} else if (!option2.equals(other.option2))
    			return false;
    		if (option3 == null) {
    			if (other.option3 != null)
    				return false;
    		} else if (!option3.equals(other.option3))
    			return false;
    		if (option4 == null) {
    			if (other.option4 != null)
    				return false;
    		} else if (!option4.equals(other.option4))
    			return false;
    		if (qid != other.qid)
    			return false;
    		if (question == null) {
    			if (other.question != null)
    				return false;
    		} else if (!question.equals(other.question))
    			return false;
    		return true;
    	}
    }
**ConnectionFac.java**

    package exam.utilities;
    import java.sql.*;
    
    public class ConnectionFac {
    
    	
    	Connection cn = null;
    	Statement st = null;
    	ResultSet rs = null;
    	
    	public Connection getConn() {
    
    		try {
    			Class.forName("com.mysql.jdbc.Driver");// Register and load driver
    			cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/exam", "root", "root");
    
    		} catch (ClassNotFoundException e) {
    			e.printStackTrace();
    		} catch (SQLException se) {
    			se.printStackTrace();
    		}
    		return cn;
    	}
    
    	public Statement getStatement() {
    		try {
    			cn = this.getConn();
    			st = cn.createStatement();
    		} catch (SQLException se) {
    			se.printStackTrace();
    		}
    		return st;
    	}
    
    	public ResultSet getResultSet(String sql) {
    		try {
    			st = this.getStatement();
    			rs = st.executeQuery(sql);
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    		return rs;
    	}
    
    }

