怎么控制循环?

frank1197 2008-07-29 12:00:47
在画面初期化的时候,页面就想显示固定的20条记录,用这个标签能不能实现...

<%
for(int i = 0;i<20;i++) {
%>
<tr>fafafa</tr>
<% } %>

就是想用<logic:iterate>标签代替上面的代码.....
...全文
413 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jyq0105 2008-07-29
  • 打赏
  • 举报
回复
那你就给这固定的20条数据不就得了啊
lyric1812 2008-07-29
  • 打赏
  • 举报
回复
<logic:notEmpty name="lstPaper" scope="request">
<logic:iterate id="paperManage" name="lstPaper" type="cn.ujn.lunwen.manager.PaperManage" scope="request">
<tr>
<td>
<bean:write name="paperManage" property="lwzwmc" scope="page"/>
</td>
<td>
<bean:write name="paperManage" property="kwmc" scope="page"/>
</td>
<td align="center">
<bean:write name="paperManage" property="fbrq" scope="page"/>
</td>
<td align="center">
院[<bean:write name="paperManage" property="checka" scope="page"/>]
校[<bean:write name="paperManage" property="checkb" scope="page"/>]
</td>
<td>
[<a href="/lunwen/paperMng.do?method=goModifyPaperPage&PaperNo=${paperManage.lwbh}&UserId=${rybh}" target="mainFrame">修改</a>]
[<a href="/lunwen/paperMng.do?method=goDeletePaperPage&PaperNo=${paperManage.lwbh}&UserId=${rybh}" target="mainFrame">删除</a>]
</td>
</tr>
</logic:iterate>
</logic:notEmpty>
hx2044 2008-07-29
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 zhangjg2124 的回复:]
加这两个属性:length="20" offset="0" offset是设置开始的位置(“0”表示第一条),你也可以设置成其他地方开始
[/Quote]
zhangjg2124 2008-07-29
  • 打赏
  • 举报
回复
加这两个属性:length="20" offset="0" offset是设置开始的位置(“0”表示第一条),你也可以设置成其他地方开始
hanyu51766 2008-07-29
  • 打赏
  • 举报
回复
用logic:iterate 里的 length offset属性来实现
skylovehang 2008-07-29
  • 打赏
  • 举报
回复
给你看个实例,自己钻研下
<logic:notEmpty name="OutListForm" property="list">
<logic:iterate name="OutListForm" property="list" id="vo"
type="com.neusoft.wms.outwarehouse.outlist.form.OutListMovementForm">
<%index++; %>
<tr>

<td nowrap=true class=singleDetailData width="25">
<input type="checkbox" name='chk'
value='<bean:write name="vo" property="rowId"/>'
id='<bean:write name="vo" property="rowId"/>' />
</td>
<td nowrap=true class=singleDetailData width="">
<bean:write name="vo" property="billNo" />
</td>
<td nowrap=true class=singleDetailData width="">
<bean:write name="vo" property="originNo" />
</td>
<td nowrap=true class=singleDetailData width="">
<bean:write name="vo" property="businessDate" />
</td>
<td nowrap=true class=singleDetailData width="">
<bean:write name="vo" property="lovName" />
</td>
<td nowrap=true class=singleDetailData width="">
<input type="hidden" name="mainstatus[<%=index%>]" id="mainstatus[<%=index%>]" value='<bean:write name="vo" property="status" />'/>
<span id="status[<%=index%>]"></span>
<script language="javascript">
<!--
var status = '<bean:write name="vo" property="status" />';
var transferstatus =( status == '0' ? "初始" :
(status == '1' ? "已下架":"已记账"));
document.getElementById("status[<%=index%>]").innerHTML=transferstatus;
-->
</script>
</td>
<td nowrap=true class=singleDetailData width="" align="right">
<bean:write name="vo" property="totalQty"/>
</td>
</tr>
</logic:iterate>
</logic:notEmpty>

估计你看的懂
Tongates 2008-07-29
  • 打赏
  • 举报
回复
<logic:iterate id="aList" name="YourForm" property="YourDataList" indexId="indexId" length="20" offset="0">

offset指定从list的那个元素开始,length指定从list中取得多少个元素
phon_oy 2008-07-29
  • 打赏
  • 举报
回复
<%
Vector animals = new Vector();
animals.addElement("Dog");
animals.addElement("Cat");
animals.addElement("Bird");
animals.addElement("Chick");
request.setAttribute("Animals", animals);
%>
<logic:iterate id="element" name="Animals">
<bean:write name="element"/><br>
</logic:iterate>
我就是靠这个文档实现logic:iterate循环
struts 标签 logic:iterate使用 logic:iterate

第一页 是struts官方的说明,
第二页 是个例子
第三页 是我实现的arrayList放入标签的方法。
这是页面文件
<%@ page language="java"
import="java.util.*,cn.edu.bit.zgc2d.accountQuery.*" pageEncoding="GBK"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic"
prefix="logic"%>









<%@ include file="../menu.txt"%>









账务查询


基本信息查询。














基本信息查询。







<logic:iterate id="item" name="list" indexId="index">





logic:iterate>

帐号

帐户别名

是否为主帐户

">







这是action
public class InformationAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
InformationForm informationForm = (InformationForm) form;// TODO Auto-generated method stub
//业务开始
Connection conn = null; Statement st = null; ResultSet rs = null;
try {
db db = new db();
// 打开数据库
conn = db.conn();
// 创建st
st = conn.createStatement();
// 组织sql并执行
HttpSession session_account = request.getSession();
String account = (String) session_account.getAttribute("account");
String sql = "select * from account where main_account=" + account
+ "order by is_main_account desc";
rs = st.executeQuery(sql);
// 组建arrayList列表
ArrayList list = new ArrayList();
while (rs.next()) {
accountBean bean = new accountBean();
bean.setArea(rs.getString("area")); bean.setKind(rs.getInt("kind")); bean.setAccount(rs.getString("account")); bean.setMain_account(rs.getString("main_account")); bean.setType(rs.getInt("type")); bean.setOther_name(rs.getString("other_name")); bean.setPassword(rs.getString("password")); bean.setIs_main_account(rs.getInt("is_main_account")); bean.setMoney(rs.getString("money")); bean.setId(rs.getInt("id"));
list.add(bean);
}
HttpSession session = request.getSession();
session.setAttribute("list", list);
return mapping.findForward("success");
} catch (Exception e) { e.printStackTrace(); }
//业务结束
return null;
}
}//自己将需要的包导入
bean文件
package cn.edu.bit.zgc2d.accountQuery;

public class accountBean {
private String area;
private int kind;
private String account;
private String main_account;
private int type;
private String other_name;
private String password;
private int is_main_account;
private String money;
private int id;
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public int getKind() {
return kind;
}
public void setKind(int kind) {
this.kind = kind;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getMain_account() {
return main_account;
}
public void setMain_account(String main_account) {
this.main_account = main_account;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getOther_name() {
return other_name;
}
public void setOther_name(String other_name) {
this.other_name = other_name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getIs_main_account() {
return is_main_account;
}
public void setIs_main_account(int is_main_account) {
this.is_main_account = is_main_account;
}
public String getMoney() {
return money;
}
public void setMoney(String money) {
this.money = money;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧