Я пытаюсь создать страницу с множественным выбором html и вам нужно использовать jsp для просмотра результатов. Тем не менее, я не могу понять, как получить файл jsp, чтобы получить окончательные результаты оценки после нажатия кнопки отправки. (например, вы получили _ из 4 вопросов правильно _%) Я могу настроить html-файл просто отлично. Что я делаю не так? Благодарю.JSP образец выбор викторины
Ниже приведен пример страницы с HTML код "SampleQuiz.html"
<html>
<head>
<title>Multiple-Choice Quiz Example</title>
</head>
<h2>Sample Multiple-Choice Quiz</h2>
<form action="quizresults.jsp" method="get">
<h3>Q1. What color is the sky on a sunny day?</h3>
<input type="radio" name="answer1" value="blue" checked="checked">blue<br>
<input type="radio" name="answer1" value="red">red<br>
<input type="radio" name="answer1" value="green">green<br>
<h3>Q2. The sum of two and three equals...</h3>
<input type="radio" name="answer2" value="seven">seven<br>
<input type="radio" name="answer2" value="six">six<br>
<input type="radio" name="answer2" value="five" checked="checked" >five<br>
<h3>Q3. Which of these animals is NOT an mammal.</h3>
<input type="radio" name="answer3" value="lizard" checked="checked">lizard<br>
<input type="radio" name="answer3" value="monkey">monkey<br>
<input type="radio" name="answer3" value="dog">dog<br>
<h3>Q4. Santa Claus is most associated with this holiday.</h3>
<input type="radio" name="answer4" value="Halloween">Halloween<br>
<input type="radio" name="answer4" value="Christmas"checked="checked">Christmas<br>
<input type="radio" name="answer4" value="Fourth of July">Forth of July<br>
<br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
Обновление: вот моя вторая попытка JSP. Я также изменил html на предложение ниже ответа.
ниже моя попытка JSP-код "quizresults.jsp"
<html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Final Quiz Score</title>
</head>
<body>
<h1>Here are your results</h1>
<%
if(request.getParameter("answer") != null) {
if(request.getParameter("answer").equals("answer1")) {
out.println("Question 1 was correct<br>");
}
else {
out.println("Question 1 was incorrect. Try again.<br>");
}
if(request.getParameter("answer").equals("answer2")) {
out.println("Question 2 was answered.<br>");
}
else {
out.println("Question 2 was incorrect. Try again.<br>");
}
if(request.getParameter("answer").equals("answer3")) {
out.println("Question 3 was answered.<br>");
}
else {
out.println("Question 3 was incorrect. Try again.<br>");
}
if(request.getParameter("answer").equals("answer4")) {
out.println("Question 4 was correct.<br>");
}
else {
out.println("Question 4 was incorrect. Try again.<br>");
}
}
%>
<form action="SampleQuiz.html" method="post">
<input type="submit" value="Return">
</form>
</body>
</html>
Спасибо. Я думал, что мне нужно изменить только значение, а не имя. Кроме того, поэтому я изменяю getParameter с «вопросов» на ответы «на jsp, правильно? – user3047713
Нет, не правильно. Прочтите мой ответ. Он рассказывает вам, что делать. –