日期:2014-05-19 浏览次数:20697 次
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<c:set var="money" value="6000" />
<c:set var="price" value="300"/>
<c:set var="price1" value="300"/>
<c:forEach var="i" begin="0" end="1000" step="1">
<c:if test="${price < money }">
<c:set var="price" value="${price + price1 }"/>
<c:out value="${price}"></c:out>
<br>
</c:if>
</c:forEach>
</body>
</html>
package com.csdn.test;//必须要有包路径不能使用default
import java.util.ArrayList;
import java.util.List;
public class MyUtils{
public static List<String> getValue(int money ,int price ,int price1 )throws Exception{
List<String> list = new ArrayList<String>();
while (price < money) {
price = price + price1;
list .add(String.valueOf(price));
}
return list;
}
}
<!-- 同理也可以动态传值 -->
<s:set name="myValue" value="@com.csdn.test.MyUtils@getValue(10000,3000,3000)">
<s:iterator value="myValue">
<s:property />
</s:iterator>