0
以下のコードがあります。ログインページにリダイレクトしようとするまで、すべてが動作します。不正な状態例外が発生します。JSPリダイレクト違法状態例外
これは、応答がすでにコミットされている可能性がありますが、どこに表示されているのかわかりません。どんな助けもありがとうございます。
<div id="questionContainer">
<form method="POST">
<%
for (int ques = 1; ques < 56; ques++) {
try {
if (iterate.hasNext()) {
String[] row = (String[]) iterate.next();
if (row[0].equals("1")) {
out.println("<div class='trigger' name='trigger" + ques + "'>");
out.println("<h2 class='page-header'>Question " + ques + "</h2>");
out.println("<p id='question'>" + row[1] + "</p><br/>");
out.println("<p id='ansA'><input type='radio' name='answer" + ques + "' value='A' checked>" + row[2] + "</p>");
out.println("<p id='ansA'><input type='radio' name='answer" + ques + "' value='B' >" + row[3] + "</p>");
out.println("<p id='ansA'><input type='radio' name='answer" + ques + "' value='C' >" + row[4] + "</p>");
out.println("<p id='ansA'><input type='radio' name='answer" + ques + "' value='D' >" + row[5] + "</p><br/>");
out.println("</div>");
} else if (row[0].equals("2")) {
out.println("<div class='trigger' name='trigger" + ques + "'>");
out.println("<h2 class='page-header'>Question " + ques + "</h2>");
out.println("<p id='question'>" + row[1] + "</p><br/>");
out.println("<p id='ansA'><input type='radio' name='answer" + ques + "' value='A'checked>" + row[2] + "</p>");
out.println("<p id='ansA'><input type='radio' name='answer" + ques + "' value='B'>" + row[3] + "</p>");
out.println("<p id='ansA'><input type='radio' name='answer" + ques + "' value='C'>" + row[4] + "</p>");
out.println("<p id='ansA'><input type='radio' name='answer" + ques + "' value='D'>" + row[5] + "</p>");
out.println("<p id='ansA'><input type='radio' name='answer" + ques + "' value='E'>" + row[6] + "</p><br/>");
out.println("</div>");
} else if (row[0].equals("3")) {
out.println("<div class='trigger' name='trigger" + ques + "'>");
out.println("<h2 class='page-header'>Question " + ques + "</h2>");
out.println("<p id='question'>" + row[1] + "</p><br/>");
out.println("Answer: <p id='ansA'><input type='text' name='answer" + ques + "'</p><br/><br/>");
out.println("</div>");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
%>
</form>
<button type="button" id="Next" name="Next">Next</button> <button type="submit" value="submited" class="submitBtn" id="Submit" name="Submit">Submit</button>
</div>
<script>
var $curCount = 1;
$(document.getElementsByName("trigger" + $curCount)).show();
$(document.getElementById("Next")).click(function() {
$(document.getElementsByName("trigger" + $curCount)).hide();
$curCount++;
$(document.getElementsByName("trigger" + $curCount)).show();
if ($curCount > 55)
{
//$(document.getElementsByName("trigger" + $curCount)).hide();
$curCount = 1;
$(document.getElementsByName("trigger" + $curCount)).show();
//window.alert("in loop" + $curCount);
$(document.getElementsByName("Submit")).show();
}
});
<% if (request.getParameter("Submit") != null && request.getParameter("Submit").equals("submited")) {
ArrayList listAnswers = new ArrayList();
for (int ques = 1; ques < 56; ques++) {
String s = request.getParameter("answer" + ques);
listAnswers.add(s);
}
con.writePAQuestions("test", listAnswers);
response.sendRedirect("main.jsp");
}
%>
</script>