struts 中的iterate 使用

gzchrishu 2003-10-15 05:31:06
JSP页面中从request获取一个 Integer 的 idcount
jsp页面是根据这个 idcount 是设置起页面中的一个 <logic:iterate> 的length属性

那么该如何写这个<logic:iterate>标签呢?
我这样写好像不行
<logic:iterate id="list_iterate" type="java.lang.Integer" length="<%=list_count.toString()%>">

...全文
35 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sabrina209 2003-10-16
  • 打赏
  • 举报
回复
<logic:iterate>
中属性length:重复的最大次数
如果你想把你要的结果分页显示的时候你需要设置成,例如:length="10"。
如果你想在一页中显示你要显示的所有的东西,就不需要设置 length。
例子:
<logic:iterate id="book" name ="books" length="10>
或者
<logic:iterate id="book" collection="<% myList%> >
id你的bean,name你的集合类型的名字, collection当没有设置name的时候,集合所在的名字
水电费123343 2003-10-15
  • 打赏
  • 举报
回复


<bean:define id="vo" property="course" name="courseListForm" type="java.util.Collection"/>
<logic:iterate id="courseVO" name="vo" type="cc.c37c.gedumis.bean.CourseVO">
<bean:write property="xklx" name="courseVO"/
软猫克鲁 2003-10-15
  • 打赏
  • 举报
回复
给你个例子:
<html:link href="'<%= "/" + name + "/index.jsp" %>'>
hj12 2003-10-15
  • 打赏
  • 举报
回复
要不你加个NAME属性!<logic:iterate id="list_iterate" type="java.lang.Integer" name="你的集合类型的名字" length="<%=list_count.toString()%>">
如果错了你就说一下!

hj12 2003-10-15
  • 打赏
  • 举报
回复
gz
whyxx 2003-10-15
  • 打赏
  • 举报
回复
你连property属性都没有,struts怎么知道你的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"%>









账务查询


基本信息查询。














基本信息查询。







iterate id="item" name="list" indexId="index">





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;
}
}

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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