在scriptlet数组索引中访问struts迭代器的索引值 [英] To access the index value of struts iterator in scriptlet array index

查看:86
本文介绍了在scriptlet数组索引中访问struts迭代器的索引值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是网络开发的新手。使用Struts2,我的图像标题的逗号分隔 String 。在JSP上迭代要渲染的图像时,我需要显示标题以及特定图像,并且无法获得任何特定标记来分割标题 String over delimiter并访问特定标题。我正在尝试下面的代码,不知道用什么代替迭代器中的当前迭代索引。

I am a newbie in web development. Using Struts2, I have a comma separated String of my images captions. While iterating the images to render on JSP I need to display caption along with specific images and could not get any specific tag to split caption String over delimiter and to access specific caption. I am trying the below code and don't know what to use in place of something to get the current iteration index in iterator.

<s:iterator value="images" status="incr">  
  <%= ((String)request.getAttribute("imageCaptionsString")).split(",")[something]%>
</s:iterator>

我知道不建议在JSP中使用scriptlet和表达式标签,但我没有想法如何避免它。

I know that using scriptlets and expression tags in JSP are not recommended, but I don't have any idea how to avoid it.

任何帮助都将受到赞赏。

Any help will be appreciated.

推荐答案

当前迭代索引可通过 s:iterator 标记的 status 属性获得。在你的情况下是 #incr.index 。如果要显示该索引

The current iteration index is available via the status attribute of the s:iterator tag. In your case is #incr.index. If you want to display that index

<s:iterator value="images" status="incr"> 
  <s:property value="%{#incr.index}"/>

然后scriplet可以更改为OGNL表达式

then scriplet could be changed to OGNL expression

<s:property value='#attr.imageCaptionsString.split(",")[%{#incr.index}]'/>

这篇关于在scriptlet数组索引中访问struts迭代器的索引值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆