关于标签logic:iterate问题?

cfpl12011124 2008-05-26 03:59:58
我用logic:iterate循环从list显示记录到jsp页面,可以正常显示
问题是:我每刷新一次就重复显示一次.
比如.正常显示:
1
2
3
第一次刷新:
1
2
3
1
2
3
请问这个问题怎么解决啊?
...全文
112 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
justforjoy 2008-05-28
  • 打赏
  • 举报
回复
大概看了下楼主的代码,心里悄悄鄙视了下,一点注释都不写…………

解决办法如三楼所说的那样。这种list属性的Attribute在使用后要记得清除…………
不然可能出现每次add的时候都是在以前的基础上ADD啦。

[Quote=引用 3 楼 binhaha 的回复:]
把代码贴出来撒
上次自己写了个迭代标签也出现过这个问题
是缓存的原因啦 你在请求接收到后先把那个Attribute清掉看看
[/Quote]
cfpl12011124 2008-05-28
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 justforjoy 的回复:]
大概看了下楼主的代码,心里悄悄鄙视了下,一点注释都不写…………

解决办法如三楼所说的那样。这种list属性的Attribute在使用后要记得清除…………
不然可能出现每次add的时候都是在以前的基础上ADD啦。



谢谢了撒,是我太大意了,每次调用Action时没有把list new一下

结贴了,
cfpl12011124 2008-05-27
  • 打赏
  • 举报
回复
JSP页面发错了,应该是这个,嘿嘿.大家都很忙.有空的帮小弟瞅瞅啊
<table align="center" width="80%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td align="left" colspan="2" bgcolor="skyblue">主 题:<bean:write name="LTReplayActionForm" property="zt"/></td>
</tr>
<tr>
<td width="20%" valign="top" bgcolor="#E6F2E7">
<table width="100%">
<tr><td align="center" valign="top">发贴人:<bean:write name="LTReplayActionForm" property="fbr"/></td></tr>
</table>
</td>
<td>
<table width="100%">
<tr bgcolor="#E6F2E7">
<td align="left">发贴时间:<bean:write name="LTReplayActionForm" property="rq"/></td><td align="right">楼主</td>
</tr>
<tr><td><bean:write name="LTReplayActionForm" property="nr"/></td></tr>
</table>
</td>
</tr>
<%int i = 1;%>
<logic:notEmpty name="list">
<logic:iterate id="templist" name="list">
<tr>
<td width="20%">
<table>
<tr><td align="center" bgcolor="#E6F2E7">回贴人:<bean:write name="templist" property="hfr"/></td></tr>
</table>
</td>
<td align="center" valign="top">
<table width="100%"><tr bgcolor="#E6F2E7"><td align="left">回贴时间:<bean:write name="templist" property="rq"/></td>
<td align="right" valign="top">回复:<font color="Red"><%=i%></font>楼</td></tr>
<tr><td align="left"><bean:write name="templist" property="neirong"/></td></tr>
</table>
</td>
<%
i++;
%>
</tr>
</logic:iterate>
</logic:notEmpty>
<tr>
<td width="20%"></td>
<td><table width="100%"><tr><td width="100%" valign="top"><html:textarea property="neirong" cols="130" rows="10"/></td></tr></table></td>
</tr>
<tr><td></td><td align="left"><html:button property="replay" value="发表" onclick="dataCheck('replay')"/></td></tr>
</table>
</html:form>
cfpl12011124 2008-05-27
  • 打赏
  • 举报
回复
这是我的Action
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)throws Exception{
ConnectDB cdb = new ConnectDB();
ResultSet resultSet = null;
resultSet = cdb.queryDataBase("select * from theme");
int data_num = 0; //记录总数
while(resultSet.next()) {
data_num++;
}
resultSet.close();
cdb.closeReslutSet();
cdb.closeStatement();
cdb.closeConnection();
int start = 1; //起始记录
int page = 10; //每页记录数
int pages = data_num/page; //取得总页数
if(data_num%page != 0)pages++;
if(request.getParameter("start") != null)
start = Integer.parseInt(request.getParameter("start"));
if(request.getParameter("go") != null) {
int go = Integer.parseInt(request.getParameter("go"));
if(go <= 1)start = 1;
else if(go > pages)
start =(pages - 1)* page +1;
else
start = (go - 1) * page + 1;
}
String sql = "select * from theme where id >='" + start + "' and id<'" + (start+page) + "'";
ResultSet result = cdb.queryDataBase(sql);
ArrayList list = new ArrayList();
while(result.next()) {
LTThemeActionForm ltForm = new LTThemeActionForm();
ltForm.setFbr(result.getString("fbr"));
ltForm.setZt(result.getString("zt"));
ltForm.setLl(result.getString("ll"));
ltForm.setRq(result.getString("rq"));
ltForm.setId(result.getInt("id"));
list.add(ltForm);
}
result.close();
request.setAttribute("list",list);
request.setAttribute("pages", new Integer(pages));
request.setAttribute("start", start);
request.setAttribute("page", page);
int previous = start - page;
if(previous >= 0) {
request.setAttribute("previous", new Integer(previous));
}
int next = start + page;
if(next <= data_num) {
request.setAttribute("next", new Integer(next));
}
return mapping.findForward("success");
}
cfpl12011124 2008-05-27
  • 打赏
  • 举报
回复
这是Jsp页面:
<html:form action="onetheme.do" method="POST">
<html:hidden property="action"/>
<table align="center" width="80%" cellpadding="2" cellspacing="0" bgcolor="#E6F2E7" border="0">
<tr><td align="right" bgcolor="White" colspan="7"></td></tr>
<tr bgcolor="SkyBlue">
<td>发贴人</td>
<td>主题</td>
<td>浏览</td>
<td align="center">日期</td>
</tr>
<%int i = 0;%>
<logic:notEmpty name="list">
<logic:iterate id="LTtheme" name="list">
<tr>
<td><bean:write name="LTtheme" property="fbr"/></td>
<td><a href="onetheme.do?action=replayList&id=<bean:write name="LTtheme"
property="id"/>"><bean:write name="LTtheme" property="zt"/></a></td>
<td><bean:write name="LTtheme" property="ll"/></td>
<td align="center"><bean:write name="LTtheme" property="rq"/></td>
</tr>
<logic:iterate>
<logic:notEmpty>
</table>
</html:form>
binhaha 2008-05-27
  • 打赏
  • 举报
回复
把代码贴出来撒
上次自己写了个迭代标签也出现过这个问题
是缓存的原因啦 你在请求接收到后先把那个Attribute清掉看看
justforjoy 2008-05-27
  • 打赏
  • 举报
回复
代码贴出来看看………………
不然让人猜太困难了吧?!
cfpl12011124 2008-05-26
  • 打赏
  • 举报
回复
咋就米人顶哩?
我就是靠这个文档实现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;
}
}

2,633

社区成员

发帖
与我相关
我的任务
社区描述
WebSphere 是 IBM 的软件平台。它包含了编写、运行和监视全天候的工业强度的随需应变 Web 应用程序和跨平台、跨产品解决方案所需要的整个中间件基础设施,如服务器、服务和工具。
社区管理员
  • WebSphere社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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