简体   繁体   English

如何使用JSP实现此模式

[英]how to implement this pattern using JSP

I'm new to using JSP and need to figure out how to do this. 我是使用JSP的新手,需要弄清楚如何做到这一点。 I'd appreciate any pointers on how to do this ? 我很欣赏有关如何做到这一点的任何指示?

I need to display images in this table-like structure. 我需要在这个类似表格的结构中显示图像。 To simplify the problem, 为了简化问题,

A  B  C
D  E  F
G  H  I

where each of these elements are a part of the Set names in action class. 其中每个元素都是动作类中Set名称的一部分。

Set<String> names = new HashSet<String>(0);

names.add("A");
names.add("B");
names.add("C");
names.add("D");
names.add("E");
names.add("F");
names.add("G");
names.add("H");
names.add("I");

Its fairly trivial to do it in java, however, I am having a hard time to figure out, how do I ask the iterator to point to next element manually. 在Java中做到这一点相当简单,但是,我很难弄清楚,如何让迭代器手动指向下一个元素。

<s:iterator value="names">
 <s:property/>
 I'd now like to point iterator to point to next or run a nested iterator loop here.
</s:iterator>

You can use JSTL forEach loop. 您可以使用JSTL forEach循环。 You can find a number of examples here . 你可以在这里找到一些例子。

You can easily accomplish it with JSTL: 您可以使用JSTL轻松完成它:

<table>
    <tr>
        <c:forEach items="names" var="name" varStatus="i">
            <c:if test="${!i.first && !i.last && i.index % 3 == 0}">
                </tr>
                <tr>
            </c:if>
            <td><c:out value="${name}" /></td>
        </c:forEach>
    </tr>
</table>

Doing so, a new line ( </tr><tr> ) will be added every 3 elements. 这样,每3个元素将添加一个新行( </tr><tr> )。

(not tested) (未测试)

As CoolBeans said, you can use JSTL forEach loop. 正如CoolBeans所说,你可以使用JSTL forEach循环。

If you'd like to see an example of that (alongside other good JSTL examples), check out JSTL Examples . 如果您想查看其中的示例(以及其他优秀的JSTL示例),请查看JSTL示例

"Iterating over data structures" has some info and examples on what you're trying to do. “遍历数据结构”提供了有关您要执行的操作的信息和示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM