如何在另一个jsp页面上获取所选单选按钮的值?

时间:2017-04-18 08:30:19

标签: java jsp

我用Java编写了一个用于在线测验的JSP程序。管理员可以提出问题,并将其存储在数据库中。学生可以从数据库中查看所有问题 现在的问题是 - 对于每个问题,有4个选项,我无法从下一个JSP程序的单选按钮读取值。这是代码

quiz.jsp

con = DriverManager.getConnection("jdbc:ucanaccess://C:/Users/LUV'S/Documents/NetBeansProjects/quiz/question.
        s = con.createStatement();
        int i=1;
        ResultSet rs= s.executeQuery("select id,question,option1,option2,option3,option4 from question where category=2");
        while(rs.next()){
        String id = rs.getString("id");
        String question = rs.getString("question");
        String option1 = rs.getString("option1");
        String option2 = rs.getString("option2");
        String option3 = rs.getString("option3");
        String option4 = rs.getString("option4");
        out.println("<div class='container'>");
        out.println("<table class='table table-bordered'>");
        out.println("<thead>");
        out.println("<tr class='danger'>");
              out.println("<th>"+i+") "+question+"</th>");
        out.println("</tr>");
        out.println("</thead>");
        out.println("<tbody>");
        out.println("<tr class='info'>");
                 out.println("<th><input type='radio' value='1' name="+id+"> "+option1+"</th>");
        out.println("</tr>");
        out.println("<tr class='info'>");
                 out.println("<th><input type='radio' value='2' name="+id+"> "+option2+"</th>");
        out.println("</tr>");
        out.println("<tr class='info'>");
                 out.println("<th><input type='radio' value='3' name="+id+"> "+option3+"</th>");
        out.println("</tr>");
        out.println("<tr class='info'>");
                   out.println("<th><input type='radio' value='4' name="+id+"> "+option4+"</th>");
        out.println("</tr>");
        out.println("</tbody>");
        out.println("</table>");
        out.println("</div>");
        i++;
       }

和examser.java

con1 = DriverManager.getConnection("jdbc:ucanaccess://C:/Users/LUV'S/Documents/NetBeansProjects/quiz/question.accdb", "", "");
    Statement s5 = con1.createStatement();
    ResultSet rs1 = s5.executeQuery("select id,answer from question where category=2");
    while (rs1.next()) {
        String answer = rs1.getString("answer");
        String id = request.getParameter("id");
        out.println(id);
    }

现在在我的数据库中我在类别2中有两个问题。当我点击提交时,它会移动到检查者并在屏幕上&#34; null null&#34;打印出来。这意味着不会读取单选按钮的值。你能告诉我哪里出错吗?

0 个答案:

没有答案