我有一个 JSP,我试图从我的模型中打印出值,但在我引用这些值的地方没有出现任何内容。这是我设置值的控制器方法。
@RequestMapping(value = "/poll1", method = RequestMethod.POST)
public String processPoll1(@RequestParam String vote,
HttpServletResponse response, Model model) {
Map<String, Object> resultMap = poll1DAO.tallyVote(vote);
Cookie poll1 = new Cookie("poll1", "voted");
model.addAttribute("poll1Yes", resultMap.get("yes").toString());
model.addAttribute("poll1No", resultMap.get("no").toString());
poll1.setMaxAge(maxSeconds);
response.addCookie(poll1);
return "redirect:/polls";
}
这是我引用模型属性的 JSP 部分。
<table>
<tr>
<td><b><i>Poll #1 -- </i></b>Would you like to have a 30-year reunion in 2016?<br></td>
</tr>
<tr>
<td><b>Yes</b></td>
<td> – <c:out value='${model.poll1Yes}' /><br /></td>
</tr>
<tr>
<td><b>No</b></td>
<td> – <c:out value='${model.poll1No}' /><br />
</td>
</tr>
</table>
这是我的输出。而不是实际值,在属性的位置没有打印任何内容。
Poll #1 -- Would you like to have a 30-year reunion in 2016?
Yes –
No –