在jsp foreach中保留控制器的索引
我在 jsp 中有一个 forEach 循环,它循环遍历对象列表并显示每个对象的 html 表数据。我希望在每个表下都有一个针对不同数据格式的导出链接,并且我能够将对象列表传递到导出控制器。
我的问题是:由于我每次都通过 jsp 循环访问控制器,所以我不知道如何保留索引,因此我只能导出当前对象。我是否
1.) 在 jsp 循环中放置一个计数器并将其传递给控制器以确定当前列表索引?
2.) 在我的实现类中是否有某种计数器,每次我从 jsp 访问时都会增加并保留其值?
或者有更好的方法吗?
I have a forEach loop in a jsp that loops through a list of objects and displays html table data for each object. I want to have an export link under each table for different data formats and I am able to pass the list of objects to an export controller.
My question is: Since I am going to the controller each time though the jsp loop, I don't know how to retain the index so I can export the current object only. Do I
1.) Put a counter in the jsp loop and pass it to the controller to determine the current list index?
2.) Have some kind of counter in my implementation class that will increment and retain its value each time I come through from jsp?
or is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定“每次通过 jsp 循环进入控制器”是什么意思。您应该只点击控制器一次,此时您的控制器应该将元素列表放入模型中。
对于索引,您需要使用
varStatus
属性。该对象有一个index
属性。请参阅此处。例如:
I'm not sure what you mean by "going to the controller each time through the jsp loop". You should only be hitting the controller once, and that's when your controller should be putting your list of elements into the model.
For the index, you want to use the
varStatus
attribute. This object has anindex
property. See here.For example: