将 ArrayList 从 Servlet 传递到 JSP
形式返回一个字符串数组列表到 servlet
ArrayList<String> currentCustomer = model.getAllCustomers();
我的模型以我想要将此数组列表从 servlet 传递到 jsp 页面的 。我该怎么做?下面是我尝试过的
req.setAttribute("currentCustomer", currentCustomer);
,在 jsp 页面中,我想使用 JSTL 循环每个值并显示它。我该怎么做?这让我非常沮丧。我在网上搜索但无济于事。非常感谢任何帮助。
这是jsp代码
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<body>
<div>
<c:forEach var="customer" items="currentCustomer">
${customer}
</c:forEach>
</div>
</body>
my model returns an arraylist of strings to servlet in the form
ArrayList<String> currentCustomer = model.getAllCustomers();
i want to pass this arraylist from the servlet to the jsp page. how do i do this? below is what i tried
req.setAttribute("currentCustomer", currentCustomer);
and in the jsp page, i want to use JSTL to loop over each value and display it. how do i do that? its frustrating me to no end. ive scoured the web but to no avail. any help is greatly appreciated.
here is the jsp code
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<body>
<div>
<c:forEach var="customer" items="currentCustomer">
${customer}
</c:forEach>
</div>
</body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它将像 smt
It will be smt like
它的 allrite 伙计们,我解决了问题..感谢您的帮助..
显然我使用的代码已经过时(感谢互联网!)我在标题上写了这个:
虽然它应该是
its allrite guys, i solved the problem.. thanks for your help..
apparently the code i was using was outdated (thanks internet!) i was writing this on the header:
while it should have been
让我们让它工作吧:)
PS jsp:useBean 是另一种方法...
PPS 我还在 taglib 导入中进行了更正。当您查看两个不同的条目并认为它们是相同的时,这就是这些明显的错误之一:)
Let's make it work :)
P.S. jsp:useBean is another way to go...
P.P.S. I also made a correction in the taglib import. That's one of these hard-visible mistakes when you can look on two different entries and think they are the same :)