ognl的作用是什么_ognl_java(5)

电脑杂谈  发布时间:2017-02-12 18:23:05  来源:网络整理

效果如下图所示:

Iterator:标签用于对集合进行迭代,这里的集合包含List、Set,Map和数组。

value:可选属性,指定被迭代的集合,如果没有设置该属性,则使用ValueStack栈顶的集合。

var: 可选属性,引用变量的名称.

status:可选属性,该属性指定迭代时的IteratorStatus实例。该实例包含如下几个方法:

int getCount(),返回当前迭代了几个元素。

int getIndex(),返回当前迭代元素的索引。

boolean isEven(),返回当前被迭代元素的索引是否是偶数

boolean isOdd(),返回当前被迭代元素的索引是否是奇数

boolean isFirst(),返回当前被迭代元素是否是第一个元素。

boolean isLast(),返回当前被迭代元素是否是最后一个元素。ognl

实例:

s_iterator.jsp

<%@ page language=java contentType=text/html; charset=UTF-8
    pageEncoding=UTF-8%>
<%@ taglib uri=/struts-tags prefix=s%>
<%@ page import=java.util.*%>
<%@ page import=ognl.*%>
<!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://.w3.org/TR/html4/loose.dtd>
<html>
<head>
<meta http-equiv=Content-Type content=text/html; charset=UTF-8>
<title>标签学习</title>
</head>
<body>
    <%
        List<String> usersList = new ArrayList<String>();
        usersList.add(张一);
        usersList.add(张二);
        usersList.add(张三);
        usersList.add(张四);
        pageContext.setAttribute(usersList, usersList);
    %>
    <hr>
    <table border=1 width=80% align=center>
        <tr>
            <th>索引号</th>
            <th>编号</th>
            <th>姓名</th>
            <th>是否奇数行</th>
            <th>是否偶数行</th>
            <th>是否第一行</th>
            <th>是否最后一行</th>
            <th>状态</th>
        </tr>
        <s:iterator var=user value=#attr.usersList status=userstatus>
            <%-- <tr style=color:<s:property value=#userstatus.odd?red:blue/>> --%>
            <tr
                style=background-color:<s:property value=#userstatus.odd?grey:green/>>
                <td><s:property value=#userstatus.index /></td>
                <td><s:property value=#userstatus.count /></td>
                <td><s:property value=#user /></td>
                <td><s:property value=#userstatus.even /></td>
                <td><s:property value=#userstatus.odd /></td>
                <td><s:property value=#userstatus.first /></td>
                <td><s:property value=#userstatus.last /></td>
                <td><s:if test=#userstatus.count==1>A</s:if> <s:elseif
                        test=#userstatus.count==2>B</s:elseif> <s:elseif
                        test=#userstatus.count==3>C</s:elseif> <s:elseif
                        test=#userstatus.count==4>D</s:elseif></td>
            </tr>
        </s:iterator>
    </table>
</body>
</html>


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-32033-5.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...