JSP 表单和 Struts 1
我制作了一个JSP表单。它包含一个简单的 MCQ 列表,其中包含每个问题的每个选项的单选按钮。
如何制作一个 struts 1 表单来检索用户选择的答案并将它们与类中定义的正确答案进行比较。
如果用户的选项正确,它应该显示用户的答案并打印“正确”。
更新 1:
<html:form action="/Ans" >
<h3>What is 2+2</h3>
1<html:radio name="MCQForm" property="usrAnswers" value="1" disabled="false"/><br>
4<html:radio name="MCQForm" property="usrAnswers" value="4" disabled="false"/><br>
2<html:radio name="MCQForm" property="usrAnswers" value="2" disabled="false"/><br>
<html:submit value="Submit" />
</html:form>
我已成功为一个问题创建了一个简单的 MCQ。
现在我将如何实现一个数组。我将如何映射第二个单选按钮并将它们与包含每个问题的正确答案的 Answers[] Array
的第二个索引进行比较。
I have made a JSP form. It contains a simple a list of MCQ's that contains radio buttons for each option for every question.
How do I make a struts 1 form that retrieves the users selected answers and compare them to the right answers which are defined in the class.
It should display the users answers and print "correct" if the users option was the correct one.
UPDATE 1:
<html:form action="/Ans" >
<h3>What is 2+2</h3>
1<html:radio name="MCQForm" property="usrAnswers" value="1" disabled="false"/><br>
4<html:radio name="MCQForm" property="usrAnswers" value="4" disabled="false"/><br>
2<html:radio name="MCQForm" property="usrAnswers" value="2" disabled="false"/><br>
<html:submit value="Submit" />
</html:form>
I have managed to create a simple MCQ for one question.
Now how will i Implement an array. How will I map the 2nd radio buttons and compare them with the 2nd index of Answers[] Array
which contains the right answer for every question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两种方法可以做到这一点:
要么您有一个包含问题的所有指定属性的操作表单,例如
,或者有一个包含数组(在本例中为字符串)的类。这比较棘手,因为您必须以某种方式将数组映射到 QuestionId。
示例:
然后您的 JSP 将是这种类型的(针对您需要的所有答案字段重复多次):
我希望这会有所帮助!
There are 2 ways of doing this:
Either you have an action form that has all specified attributes for your questions e.g.
OR, have a class that has an array (of String, in this case). This is more tricky as you will have to map your array to a questionId somehow.
Example:
and then your JSP will be something of this sort (repeated many times for all the answer fields you need):
I hope this helps!