0

我正在尝试进行在线测试,但是当我单击按钮转到测试页面时,此页面未打开。这是该程序的一部分:

try{
    int i=1;
    Random rand =new Random();
    int newrand=rand.nextInt(9);
    session.setAttribute("aptirandom",String.valueOf(newrand));
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","12345");
    String admitid=session.getAttribute("admitid").toString();
    int aid=Integer.parseInt(admitid); 
    PreparedStatement ps1=con.prepareStatement("select aptikey from result where admitid=?");
    ps1.setInt(1,aid);
    ResultSet rs1=ps1.executeQuery();
    rs1.next();
    if(rs1.getInt("aptikey")==1)
                   {
                    response.sendRedirect("AlreadyExam.jsp");
                    }
           else
           {
    PreparedStatement ps=con.prepareStatement("select * from aptitude where qid>? order by qid");
    ps.setInt(1,newrand);
    ResultSet rs=ps.executeQuery();
        while(rs.next() && i<=10)
        {
    %>


    <form action="AptitudeResult.jsp" align="left" name="AptiForm">


        <P><b><%=i%>. <%=rs.getString("question")%></b><BR><BR>  
<input type="radio" name="answer<%=i%>" value="<%=rs.getString("option1")%>"><font color="blue">&nbsp;&nbsp;A.&nbsp;&nbsp;</font><%=rs.getString("option1")%>&nbsp;

" value="<%=rs.getString("option2")%>"> B. <%=rs.getString("option2")%>

" value="<%=rs.getString("option3")% >"> C. <%=rs.getString("option3")%> " value="<%=rs.getString("option4")%>"> C. <%=rs.getString("option4") %>

             <%
                i++;
                     } rs.close();
                        ps.close();        
                        } 
                     con.close();
                     rs1.close();
                     ps1.close();


    }
    catch(NullPointerException e)
                          {
        response.sendRedirect("CandidateLogin.jsp");
    }

            %>

<p><input style="padding-top: 25px; font: 100% arial; border: 1px solid; width: 170px; margin: 0 0 0 212px; height: 33px; padding: 2px 0 3px 0;cursor: pointer;background: #7D0F0F; color: #FFF;"  class="submit" type="submit" name="TestButton" onclick="DoneTest()" value="Submit Aptitude Test"></p>


                    </form>
                    </div>
                           </div>




  <div id="content_footer"></div>

  <div id="footer" >
Copyright © All Rigths Reserved  
  </div>

  </div>
            </body>
                   </html>

Coding of aptituderesult.jsp is below : 

身体>

    <div id="main">

    <div id="header">
            <div id="logo">
                 <div id="logo_text">

      <h1>Online Recruitment System</h1>

                </div>
            </div>
    </div>




  <div id="site_content">

  <div id="content">

 <%

try{
    String demo,answer,option;

 Connection con=null;
 String id;
 int aptimarks=0;
 int qid;
 int total=0;
 int i=1;
  String random=session.getAttribute("aptirandom").toString();
 try{

  Class.forName("oracle.jdbc.driver.OracleDriver");
  con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","12345");
           }
 catch(Exception e)
                     {
     e.printStackTrace();
   }

    PreparedStatement ps=con.prepareStatement("select * from aptitude where qid>? order by qid");
    ps.setString(1,random); 
    ResultSet rs=ps.executeQuery();
    while(rs.next()){
        answer=rs.getString("answer");
        qid=rs.getInt("qid");
        id=String.valueOf(i);
        demo="answer".concat(id);
        option=request.getParameter(demo);
        if(answer.equals(option))
        {
            aptimarks++;
        }
        i++;
    }


    String admitid=session.getAttribute("admitid").toString();
    int aid=Integer.parseInt(admitid); 


    PreparedStatement ps1=con.prepareStatement("select total from result where admitid=?");
    ps1.setInt(1,aid);
    ResultSet rs1=ps1.executeQuery();
    rs1.next();
    total=rs1.getInt("total");
    total=total+aptimarks;


    PreparedStatement ps2=con.prepareStatement("update result set aptiresult=?,aptikey=1,total=? where admitid=?");
    ps2.setInt(1,aptimarks);
    ps2.setInt(2,total);
    ps2.setInt(3,aid);
    ps2.executeUpdate();



    response.sendRedirect("TestHome.jsp");

        }
catch(NullPointerException e)
           {
    response.sendRedirect("TestHome.jsp");
}

%>

                </div>
                           </div>




  <div id="content_footer"></div>

  <div id="footer" >
  Copyright : Inderjeet Singh |Designed in JSP | JAVA | Struts |
  </div>

  </div>
            </body>
                   </html>
4

1 回答 1

0

如果条件 bcz 你不能直接调用 rs1.getInt("") 方法,请将你的 rs1.next() 保留在里面。

于 2013-05-10T04:56:53.427 回答