ArrayList 的 ArrayList - 使用 EL 访问值
我有一个 Arraylist< 的 Arraylist String>'s,我正在尝试访问字符串值。假设我想访问 jsp 文件中第二个 ArrayList 中的第三个字符串,但我想在不编写脚本的情况下使用 EL 来完成此操作。这是正确的吗? ${anArrayList[2][3]}
I have an Arraylist of Arraylist< String>'s and I am trying to access a string value. Say I wanted to access the third String in the second ArrayList in my jsp file, but I wanted to do it without scripting, using EL. would this be correct? ${anArrayList[2][3]}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几乎是正确的。数组索引以
0
开头,而不是您想象的那样以1
开头。在普通 Java 代码中一直都是这种情况,在 EL 中也没有什么不同。因此,要获取第二个列表和第三个字符串,您分别需要索引1
和2
。因此,这应该可以...假设您已经将
${anArrayList}
放置在所需的范围内。例如,在请求范围内借助预处理servlet:顺便说一句,您熟悉Javabean?这听起来很像你更需要一个
List
。Almost correct. Array indexes start with
0
, not1
as you seem to think. This has always been the case in normal Java code and this is not different in EL. So, to get the second list and then the third string, you need respectively the indexes1
and2
. So, this should do...assuming that you've already placed
${anArrayList}
in the desired scope. For example, in the request scope with help of a preprocessing servlet:By the way, are you familiar with Javabeans? This smells much that you rather need a
List<Entity>
.