<s:set name="start" value="10" /> //start是从前一个页面中传递过来的参数
<s:set name="end" value="30" /> //end是从前一个页面中传递过来的参数
<s:bean name="org.apache.struts2.util.Counter" id="counter">
<s:param name="first" value="%{#start}" /><!-- 可以控制开始和结束 -->
<s:param name="last" value="%{#end}" />
<s:iterator>
<s:property/>
</s:iterator>
</s:bean>
org.apache.struts2.util.Counter源码
/*
* $Id: Counter.java 471756 2006-11-06 15:01:43Z husted $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts2.util;
import java.io.Serializable;
/**
* A bean that can be used to keep track of a counter.
* <p/>
* Since it is an Iterator it can be used by the iterator tag
*
*/
public class Counter implements java.util.Iterator, Serializable {
private static final long serialVersionUID = 2796965884308060179L;
boolean wrap = false;
// Attributes ----------------------------------------------------
long first = 1;
long current = first;
long interval = 1;
long last = -1;
public void setAdd(long addition) {
current += addition;
}
public void setCurrent(long current) {
this.current = current;
}
public long getCurrent() {
return current;
}
public void setFirst(long first) {
this.first = first;
current = first;
}
public long getFirst() {
return first;
}
public void setInterval(long interval) {
this.interval = interval;
}
public long getInterval() {
return interval;
}
public void setLast(long last) {
this.last = last;
}
public long getLast() {
return last;
}
// Public --------------------------------------------------------
public long getNext() {
long next = current;
current += interval;
if (wrap && (current > last)) {
current -= ((1 + last) - first);
}
return next;
}
public long getPrevious() {
current -= interval;
if (wrap && (current < first)) {
current += (last - first + 1);
}
return current;
}
public void setWrap(boolean wrap) {
this.wrap = wrap;
}
public boolean isWrap() {
return wrap;
}
public boolean hasNext() {
return ((last == -1) || wrap) ? true : (current <= last);
}
public Object next() {
return new Long(getNext());
}
public void remove() {
// Do nothing
分享到:
相关推荐
fortoken</li><br> ${tokenstr}" delims="," var="v"> ${v}"/> </c:forTokens> <p><br> 循环控制标签:c:foreach-map</li><br> ${map}" var="v"> ${v} <br> ${v.key}=${v.value } ...
循环判断语句<xsl:for-each> 392 条件判断语句<xsl:if> 392 内容总结 395 独立实践 395 第二十二章:使用Java解析XML 397 学习目标 397 解析器的介绍 398 DOM以及广义的基于树的处理具有几个优点 399 文档对象模型...
Struts2是如何实现MVC模式的? 答:在Struts2里面是将每次页面的请求进行处理,然后将请求需要输出的数据转发到需要做数据显示的页面。Struts2只是起到一个数据接收和转接的功能,就是Controller控制器,而传来数据...
16、在JAVA 中,如何跳出当前的多重嵌套循环? 9 17、构造器Constructor 是否可被override? 9 18、两个对象值相同(x.equals(y) == true),但却可有不同的hash code,这句话对不对? 9 19、是否可以继承String 类? 9 ...
16、在JAVA 中,如何跳出当前的多重嵌套循环? 9 17、构造器Constructor 是否可被override? 9 18、两个对象值相同(x.equals(y) == true),但却可有不同的hash code,这句话对不对? 9 19、是否可以继承String 类? 9 ...
JAVA模版引擎Freemarker常用标签(一) 1. if指令 这是一个典型的分支控制指令,该指令的作用完全类似于Java语言中的if,if指令的语法格式如下: <#if condition>... <#elseif condition>... <#elseif condition>......
HashMap是Hashtable的轻量级实现(非线程安全的实现),他们都完成了Map接口,主要区别在于HashMap允许空(null)键值(key),由于非线程安全,效率上可能高于Hashtable。 HashMap允许将null作为一个entry的key或者...
for(int i=0;i<2;i++){ Thread t=new Thread(inc); t.start(); t=new Thread(dec); t.start(); } } private synchronized void inc(){ j++; System.out.println(Thread.currentThread().getName()+"-inc:"+j); } ...
,能在模板变量,变量属性引用,for循环,占位符输出,try-catch中等各个地方提供安全输出,保证渲染正常。5、模板变量:运行将模板的某一部分输出像js那样赋值个一个变量,稍后再处理。利用模板变量能完成非常复杂...
其中使用Struts作为系统的整体基础架构,负责MVC的分离,在Struts框架的模型部分,控制业务跳转,利用Hibernate框架对持久层提供支持,Spring做管理,管理Struts和Hibernate。 WebStorage HTML新增的本地存储解决...