Struts问题,怎样用logic:iterate显示查询结果?

Sun_Libra 2004-03-18 08:26:28
现在不明白的是怎样把查询结果传给logic:iterate显示出来,
我在bean里把查询结果放在vector里,是不是应在action里把结果传给jsp,
但是具体怎么做呢?
最好给个例子,多谢谢!
...全文
87 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
zcjl 2004-03-19
  • 打赏
  • 举报
回复
:)
楼上果然好眼力
今天出去活动了一下
想着还有问题没搞定
没想到楼上已经给出答案了
cooldoghuang 2004-03-19
  • 打赏
  • 举报
回复
看一下struts附带的struts-documentation吧,那里对struts使用的各个标签库都有详细的说明
VVV_lucky 2004-03-19
  • 打赏
  • 举报
回复
也是那么做就可以了。
logic:iterate支持Vector.
request.setAttribute("resultlist",yourVector);
cooldoghuang 2004-03-19
  • 打赏
  • 举报
回复
ArrayList aczdw = new ArrayList();
while(rs.next()){
cd.setTflxr((String)rs.getString("dwbh"));
cd.setTfwz((String)rs.getString("qymc"));

aczdw.add(cd);
}
request.setAttribute("aczdw",aczdw);
-- 你的代码中的cd在哪里定义的,必须在循环中定义!
while(rs.next()){
CD cd = new CD();
...
}
我估计你是在循环之前定义的,所以得到的是最后一个记录

再说,我并没有定义"row",为什么要改成它呢?
-- <logic:iterate id="row" name="aczdw" scope="request" >中定义了“row”,他会生成一个新的Bean,名字为"row".

Sun_Libra 2004-03-19
  • 打赏
  • 举报
回复
还是没有解决,改过后,显示为空白页,没有出错信息,
再说,我并没有定义"row",为什么要改成它呢?
zcjl 2004-03-19
  • 打赏
  • 举报
回复
<logic:iterate id="aczdw" name="aczdw" scope="request" >
<tr>
<td><bean:write name="aczdw" property="tfdwbh" /></td>
<td><bean:write name="aczdw" property="tfqymc" /></td>
</tr>
</logic:iterate>

改成
<logic:iterate id="row" name="aczdw" scope="request" >
<tr>
<td><bean:write name="row" property="tfdwbh" /></td>
<td><bean:write name="row" property="tfqymc" /></td>
</tr>
</logic:iterate>
试试看
Sun_Libra 2004-03-19
  • 打赏
  • 举报
回复
to mickey_uuu() :
我看过了,取到的是不同的记录啊,
ArrayList aczdw = new ArrayList();
while(rs.next()){
cd.setTflxr((String)rs.getString("dwbh"));
cd.setTfwz((String)rs.getString("qymc"));

aczdw.add(cd);
}
request.setAttribute("aczdw",aczdw);

没什么问题吧?可是怎么回事呢?在线等
mickey_uuu 2004-03-19
  • 打赏
  • 举报
回复
问题出在 action中 仔细检查你对rusultset的处理
Sun_Libra 2004-03-19
  • 打赏
  • 举报
回复
<logic:iterate id="aczdw" name="aczdw" scope="request" >
<tr>
<td><bean:write name="aczdw" property="tfdwbh" /></td>
<td><bean:write name="aczdw" property="tfqymc" /></td>
</tr>
</logic:iterate>
aczdw为Arraylist组,现在是显示的结果数正确,但是全是同一条记录,
显示的所有行都是最后一次取到的记录,
这是怎么回事呢?
Sun_Libra 2004-03-18
  • 打赏
  • 举报
回复
请大家关心一下,分不成问题!
Sun_Libra 2004-03-18
  • 打赏
  • 举报
回复
多谢谢回答,
现在由rs生成了vector,为什么一样要生成list?
如果用vector怎么把值给request?
showerXP 2004-03-18
  • 打赏
  • 举报
回复
nod
NewTypeQ 2004-03-18
  • 打赏
  • 举报
回复
action里面生成一个list
如resultlist
然后返回页面之前request.setAttribute("resultlist",resultlist);

.jsp中

<logic:iterate id="iterList" name="resultlist">
<bean:write name="iterList" property="a" />
<bean:write name="iterList" property="b" />
<%--假设resultlist每行含有a,b两个属性--%>
</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;
}
}

67,549

社区成员

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

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