Java “下一步”按钮将生成一组新的问题

Java “下一步”按钮将生成一组新的问题,java,jsp,servlets,Java,Jsp,Servlets,我正在尝试使用jsp和servlet创建一个在线测验系统。 当用户选择主题时,会转到第一个问题。在用户选择他们的选项并单击“下一步”按钮后,应该会显示一组新的问题和选项。我不知道该怎么做那部分。以下是我目前的代码: 数据库: public static MathQuestion getQuestionInfo(int questionNum) { MathQuestion math = new MathQuestion(); // int questionN

我正在尝试使用jsp和servlet创建一个在线测验系统。 当用户选择主题时,会转到第一个问题。在用户选择他们的选项并单击“下一步”按钮后,应该会显示一组新的问题和选项。我不知道该怎么做那部分。以下是我目前的代码:

数据库:

public static MathQuestion getQuestionInfo(int questionNum)
    {
        MathQuestion math = new MathQuestion();
      //  int questionNum = 1;
        try
        {
            Connection conn = DBConnection.getConnection();

            String query = "SELECT * FROM MathQuestions where QuestionNumber = ?";
            PreparedStatement stmt = conn.prepareStatement(query);
            stmt.setInt(1, questionNum);
        //    questionNum++;
            ResultSet rs = stmt.executeQuery();

            while(rs.next())
            {
                math.setQuestionNum(rs.getInt("QuestionNumber"));
                math.setQuestion(rs.getString("Question"));

                String questionOptions = rs.getString("QuestionOptions");
                String[] splittedValues = null;
                for(int i = 0; i < 4; i++)
                {
                   splittedValues = questionOptions.split(",");
                }
                math.setQuestionOptions(splittedValues);
                math.setCorrectAnswer("CorrectAnswer");
            }
        } 
        catch (Exception e)
        {
            System.out.println(e);
        }

        return math;
    }
公共静态MathQuestion getQuestionInfo(int questionNum)
{
MathQuestion数学=新的MathQuestion();
//int questionNum=1;
尝试
{
连接conn=DBConnection.getConnection();
String query=“从MathQuestions中选择*,其中QuestionNumber=?”;
PreparedStatement stmt=conn.prepareStatement(查询);
stmt.setInt(1,questionNum);
//问题数++;
ResultSet rs=stmt.executeQuery();
while(rs.next())
{
math.setQuestionNum(rs.getInt(“QuestionNumber”);
数学.setQuestion(rs.getString(“问题”);
String questionOptions=rs.getString(“questionOptions”);
字符串[]splittedValues=null;
对于(int i=0;i<4;i++)
{
splittedValues=questionOptions.split(“,”);
}
math.setQuestionOptions(分割值);
math.setCorrectAnswer(“CorrectAnswer”);
}
} 
捕获(例外e)
{
系统输出打印ln(e);
}
回归数学;
}
JSP


数学
数学科
问题





Servlet:

@WebServlet(name = "Math", urlPatterns =
{
    "/Math"
})
public class Math extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        if (SessionService.validateSession(request, response))
        {
            RequestDispatcher dispatcher = request.getRequestDispatcher("math-page.jsp");
            request.setAttribute("questionNum", 1);
            dispatcher.forward(request, response);
        }
        else
        {
            RequestDispatcher dispatcher = request.getRequestDispatcher("login-page.jsp");
            dispatcher.forward(request, response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        for(int i = 2; i <= 10; i++)
        {
             RequestDispatcher dispatcher = request.getRequestDispatcher("math-page.jsp");
             request.setAttribute("questionNum", i);
             dispatcher.forward(request, response);
        }

        String userChoice = request.getParameter("options");
    }
}
@WebServlet(name=“Math”,urlPatterns)=
{
“/数学”
})
公共类数学扩展HttpServlet
{
@凌驾
受保护的void doGet(HttpServletRequest请求,HttpServletResponse响应)抛出ServletException,IOException
{
if(SessionService.validateSession(请求、响应))
{
RequestDispatcher=request.getRequestDispatcher(“math page.jsp”);
setAttribute(“questionNum”,1);
转发(请求、响应);
}
其他的
{
RequestDispatcher=request.getRequestDispatcher(“login page.jsp”);
转发(请求、响应);
}
}
@凌驾
受保护的void doPost(HttpServletRequest请求、HttpServletResponse响应)引发ServletException、IOException
{
对于(int i=2;i
@WebServlet(name = "Math", urlPatterns =
{
    "/Math"
})
public class Math extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        if (SessionService.validateSession(request, response))
        {
            RequestDispatcher dispatcher = request.getRequestDispatcher("math-page.jsp");
            request.setAttribute("questionNum", 1);
            dispatcher.forward(request, response);
        }
        else
        {
            RequestDispatcher dispatcher = request.getRequestDispatcher("login-page.jsp");
            dispatcher.forward(request, response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        for(int i = 2; i <= 10; i++)
        {
             RequestDispatcher dispatcher = request.getRequestDispatcher("math-page.jsp");
             request.setAttribute("questionNum", i);
             dispatcher.forward(request, response);
        }

        String userChoice = request.getParameter("options");
    }
}