关于struts中的iterate问题 显示页面怎么不出来啊 一定给分!

jianbo99 2007-01-09 02:09:44
如题,这是显示页面的logic:iterate 部分的代码:
<logic:iterate id="ahtlete" name="allathlete" type="com.yujianbo.struts.R_athlete">
<tr class="th2">
<td height="14" align="center" valign="middle"><bean:write name="athlete" property="ath_id"/></td>
<td align="center" valign="middle"><bean:write name="athlete" property="team_name"/></td>
<td align="center" valign="middle"><bean:write name="athlete" property="ath_name"/></td>
<td align="center" valign="middle"><bean:write name="athlete" property="ath_sex"/></td>
<td align="center" valign="middle"><bean:write name="athlete" property="ath_card_id"/></td>
<td align="center" valign="middle"><bean:write name="athlete" property="ath_na_chname"/></td>
<td align="center" valign="middle"><bean:write name="athlete" property="ath_prov_chname"/></td>
<td align="center" valign="middle"><bean:write name="athlete" property="ath_level_name"/></td>
<td align="center" valign="middle"><bean:write name="athlete" property="ath_s_name"/></td>
<td align="center" valign="middle"><bean:write name="athlete" property="ath_log_date"/></td>
<td align="center"><a href="view_one_athlete.do?method=View_one&ath_id=<%//=u.getAth_id()%>" class="th2">修改</a></td>
<td align="center"><a href="del_athlete.do?method=Del&ath_id=<%//=u.getAth_id()%>&team_log_date=<%//=u.getAth_log_date()%>" class="th2">删除</a></td>
</tr>
</logic:iterate>


这是为Action里面的那段封装athletes的代码:
public ActionForward View(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws SQLException, IOException, FileUploadException{
/* File file = new File("c:\\1.jpg");*/
/*连接数据库*/
ServletContext context = servlet.getServletContext();
DataSource dataSource = (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
DB db = new DB(dataSource);
String txtsql=new String("select ath_id,team_name,ath_name,ath_sex,ath_card_id,ath_na_chname,ath_prov_chname," +
"ath_level_name,ath_log_date,s_num from R_athlete");
ResultSet rs=db.OpenSql(txtsql);
//Vector athletes=new Vector();

java.util.ArrayList allathlete = new java.util.ArrayList();



//rs.first();
while( rs.next()){
R_athlete athlete=new R_athlete();
athlete.setAth_id(rs.getString(1));
athlete.setTeam_name(rs.getString(2));
athlete.setAth_name(rs.getString(3));
athlete.setAth_sex(rs.getString(4));
athlete.setAth_card_id(rs.getString(5));
athlete.setAth_na_chname(rs.getString(6));
athlete.setAth_prov_chname(rs.getString(7));
athlete.setAth_level_name(rs.getString(8));
athlete.setAth_log_date(rs.getString(9));
athlete.setS_num(rs.getString(10));

allathlete.add(athlete);
}

HttpSession session = request.getSession();
session.setAttribute("allathlete",allathlete);
//request.setAttribute("athletes",athletes);
db.close();
return mapping.findForward("toshowathlete");
}

我在Netbeans里面调试的时候 allathlete是有值的 但是在上面那个显示页面却出不来值 不知道问题出在什么地方,希望各位高手帮我诊断一下 谢谢!一定给分
...全文
240 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jianbo99 2007-01-10
  • 打赏
  • 举报
回复
问题解决了 将session.setAttribute("allathlete",allathlete);
改成request.setAttribut(("allathlete",allathlete);就行了 谢谢各位
jianbo99 2007-01-09
  • 打赏
  • 举报
回复
楼上各位的方法我都试过了,还是不行,问题到底出在什么地方呢?期待各位高手帮我想想办法
YOYOOOP 2007-01-09
  • 打赏
  • 举报
回复
这跟写在TR里面外面没关系
我个人意思:你可以试试将ArrayList 改为List
然后request.setAttribut(("allathlete",allathlete);
Daem0n 2007-01-09
  • 打赏
  • 举报
回复
加scope="session"试下
ocean放飞 2007-01-09
  • 打赏
  • 举报
回复
同意楼上的!
xuyisun 2007-01-09
  • 打赏
  • 举报
回复
把<logic:iterate id="ahtlete" name="allathlete" type="com.yujianbo.struts.R_athlete"> 写在TR里面去看看

我就是靠这个文档实现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,542

社区成员

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

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