gpt4 book ai didi

jsp - Spring 3-在JSP中访问Model值

转载 作者:行者123 更新时间:2023-12-04 04:17:48 25 4
gpt4 key购买 nike

我有一个JSP,正在尝试从模型中打印出值,但是在我引用这些值的地方没有任何显示。这是我设置值的 Controller 方法。

@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的一部分,在这里我提到了Model属性。
<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>&nbsp;&ndash;&nbsp;<c:out value='${model.poll1Yes}' /><br /></td>
</tr>
<tr>
<td><b>No</b></td>
<td>&nbsp;&ndash;&nbsp;<c:out value='${model.poll1No}' /><br />
</td>
</tr>
</table>

这是我的输出。在属性的位置没有打印出任何实际值,而不是实际值。
Poll #1 -- Would you like to have a 30-year reunion in 2016?

Yes –

No –

最佳答案

无需在您的JSP中引用model

<c:out value='${poll1Yes}' />
<c:out value='${poll1No}' />

关于jsp - Spring 3-在JSP中访问Model值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16754470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com