オンライン テストをしようとしていますが、ボタンをクリックしてテスト ページに移動しても、このページが開きません。これがそのプログラムの一部です:
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"> A. </font><%=rs.getString("option1")%>
" 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>