我正在尝试HashMap在 jsp 页面中调用一个值,但出现错误并且错误说
出现意外错误(类型=内部服务器错误,状态=500)。对于输入字符串:“res”
我的代码;
<c:forEach items="${onlineExamList}" var="item"
varStatus="loop">
<div>
<b>${item.question1}</b><br>
<div class="radio">
<label><input type="radio" value="a"
name="answers[${loop.index}]">${item.option1}</label>
</div>
<div class="radio">
<label><input type="radio" value="b"
name="answers[${loop.index}]">${item.option2}</label>
</div>
<div class="radio">
<label><input type="radio" value="c"
name="answers[${loop.index}]">${item.option3}</label>
</div>
<div class="radio">
<label><input type="radio" value="d"
name="answers[${loop.index}]">${item.option4}</label>
</div>
<input type="text" name="rightAnswer"
value="${item.rightAnswer}">
//problem in this line
<c:if test="${result != null}">
<br>
<br>
<b>Your answer: ${result.get("res"+loop.index).get(1)}</b>
<br>
</c:if>
</div>
<hr />
</c:forEach>
这就是我从控制器设置哈希图的方式
Map<String, List<String>> mapResult = new HashMap<String, List<String>>();
int totalScore = 0;
for (int i = 0; i < answers.answers.size(); i++) {
List<String> result = new ArrayList<>();
String res = "Wrong";
if (answers.answers.get(i).equals(answers.rightAnswer.get(i))) {
res = "Correct";
totalScore+=10;
}
result.add(res);
result.add(answers.answers.get(i));
result.add(answers.rightAnswer.get(i));
mapResult.put("res" + i, result);
}
ra.addFlashAttribute("result", mapResult);
ra.addFlashAttribute("score", totalScore);
Java页面上打印的相同内容
for (int i = 0; i < 10; i++) {
System.out.println(mapResult.get("res" + i).get(0));
System.out.println(mapResult.get("res" + i).get(1));
System.out.println(mapResult.get("res" + i).get(2));
System.out.println("...................................");;
}
如何在 jsp 页面中打印 hashmap 值?