gpt4 book ai didi

java - 将HashMap传递给jsp

转载 作者:行者123 更新时间:2023-12-01 16:58:30 25 4
gpt4 key购买 nike

我正在尝试使用以下 JSP 代码显示元素列表:

                 <c:forEach items="${themesContentMap}" var="entry">
<tr>
<td><input type="checkbox" value="${entry.key.getId()}"checked></td>
<td>${entry.key.getLibelle()}</td>
<td>${entry.value.getNom()}</td>
</tr>
</c:forEach>

由java代码提供:

    HashMap<ThemeBean, CoursBean> themeContentMap = new HashMap<ThemeBean, CoursBean>();
for (ThemeBean theme : themeBeans) {
themeContentMap.put(theme, coursDAO.getCours(theme.getCours()));
}
LOG.debug("Found matching: " + themeContentMap);
request.setAttribute("themesContentMap", themeContentMap);
resp.sendRedirect(LIST_THEMES);

但是,我的网页中没有收到任何内容,日志中也没有收到任何错误(调试显示正确的信息)。

请注意,我是 servlet 和 JSP 的初学者,因此我可能会遗漏一些明显的东西。

最佳答案

sendRedirect() 将 header 发送回浏览器(302 HTTP 状态代码),并且还包含要重定向到的资源的名称。所以这将是浏览器对资源的新请求。您必须转发请求

requestDispatcher.forward(request, response);

Jsp 接受请求和属性并进一步处理它。

关于java - 将HashMap传递给jsp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29766745/

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