I have a form, if the timer reach the form will auto redirect to the Servlet to update database. My problem now is if javascript redirect the window to servlet my request.getParameter is null.
function verify(f,whichCase){
if(whichCase == "Submit"){
msg = "Are you sure that you want to submit this test?";
var i = confirm(msg)
if(i){
parent.window.location = "sindex.jsp"
}
return i;
}
}
I doing this because i got a iframe in my jsp. Timer update problem have to use iframe. So, when time up or user click submit parent.window.location can let me refresh parent window
<form method="POST" action="${pageContext.request.contextPath}/TestServlet" onSubmit="return verify(this,whichPressed)">
My form when user click submit button within the timing, it will trigger the verify function to let user confirm submit. So inside my TestServlet i got this, because using javascript redirect request.getParameter("answer") this keep return me null.
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
if (request.getParameter("Submit") != null) {
String ans = request.getParameter("answer");
Answer a = new Answer(ans, no);
aa.CreateAnswer(an,t.getTestCode(),username);
RequestDispatcher rd = request.getRequestDispatcher("/sindex.jsp");
rd.forward(request, response);
}
}
Below are my timer when time up redirect to TestServlet trigger the doGet method
if((mins == 0) && (secs == 0)) {
window.alert("Time is up. Press OK to submit the test."); // change timeout message as required
var sUrl = "TestServlet";
parent.window.location = sUrl // redirects to specified page once timer ends and ok button is pressed
} else {
cd = setTimeout("redo()",1000);
}