logic:iterate问题

hjm0803 2011-03-19 04:00:49
我在jsp中用了logic:iterate标签,可是一直没有数据显示,这是怎么回事,请大家帮帮我,谢谢
我的代码如下:
jsp代码:

<%@ page contentType="text/html;charset=GB2312" %>
<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/tlds/c.tld" prefix="c"%>
<%@ page isELIgnored="false" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
</head>
<body>
<table align="center" border="1">
<logic:empty name="userInfoList" scope="request">
<h3>抱歉:没有您的信息</h3>
</logic:empty>
<logic:notEmpty name="userInfoList" scope="request">
<logic:iterate id="student" name="userInfoList" scope="request">
<tr>
<th width="33.3%">帐号</th>
<th width="33.3%">昵称</th>
<th width="33.3%">真实姓名</th>
</tr>
<tr>
<td width="33.3%"><bean:write name="student" property="ID"/></td>
<td width="33.3%"><bean:write name="student" property="userName"/></td>
<td width="33.3%"><bean:write name="student" property="trueName"/></td>
</tr>
<tr>
<th width="33.3%">电话号码</th>
<th width="33.3%">详细地址</th>
<th width="33.3%">电子邮箱</th>
</tr>
<tr>
<td width="33.3%"><bean:write name="student" property="phone"/></td>
<td width="33.3%"><bean:write name="student" property="address"/></td>
<td width="33.3%"><bean:write name="student" property="email"/></td>
</tr>
</logic:iterate>
</logic:notEmpty>
</table>
</body>
</html>
我的action代码部分如下:
public ActionForward checkUserInfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
HttpSession session=request.getSession();
String userName=(String)session.getAttribute("userName");
if(userName==null||userName.equals(""))//若用户为空
return mapping.findForward("fail");
Map map=new HashMap();
map.put("userName",userName);
UserDao dao=new UserDaoSimple();
List list=new ArrayList();
list=dao.queryArray(map);//学生查询
request.setAttribute("userInfoList", list);//将查询结果放入request中
return mapping.findForward("studentInfo");//将数据返回查询页
}
我的queryArray方法如下:
public List queryArray(Map map) {
String sql=null;
List list = new ArrayList();
if (!map.isEmpty()) {
Set set = map.keySet();
Iterator it = set.iterator();
String column;
String value;
while (it.hasNext()) {
column = (String) it.next();
value = (String) map.get(column);
sql ="select * from [user] where " + column + "='" + value + "' ";//有点像持久化了
System.out.println(sql);
}
}
try {
con=openDB();
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {//若存在记录,则
UserBean user = new UserBean();//实例化UserBean,导入数据库中的数据
user.setID(rs.getInt("ID"));
user.setUserName(rs.getString("userName"));
user.setTrueName(rs.getString("trueName"));
user.setPassword(rs.getString("password"));
user.setPhone(rs.getString("phone"));
user.setAddress(rs.getString("address"));
user.setProblem(rs.getString("problem"));
user.setProblemAnswer(rs.getString("problemAnswer"));
user.setEmail(rs.getString("email"));
list.add(user);
}
}catch (Exception e) {
e.printStackTrace();
} finally {
closeDB(con);
}
return list;
}
...全文
100 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lolita22 2011-03-23
  • 打赏
  • 举报
回复
可能你的查询里得到的是空值吧
LoongMint 2011-03-21
  • 打赏
  • 举报
回复
LZ的这个看着貌似没有什么问题。先确定在访问页面的时候,后台报异常了吗?你可以在页面中用request.getAttribute("userInfoList")取出list 然后迭代打印。看看有无结果。如果有说明是你的iterator标签没取到值,如果没有,那自然就是没查询出结果。在代码中没有发现什么问题的话,就一步步的debug吧。慢慢来。
ZhaoMinIsAngel 2011-03-21
  • 打赏
  • 举报
回复
看看你action里是怎么存值的
Spring89 2011-03-21
  • 打赏
  • 举报
回复
logic:empty换成logic:present来试一下!
iyan84 2011-03-21
  • 打赏
  • 举报
回复
list=dao.queryArray(map);//学生查询
request.setAttribute("userInfoList", list);//将查询结果放入request中
看下list有没值,没值的话页面就是空的,如果有值,页面上就有问题
ajaxUser002 2011-03-21
  • 打赏
  • 举报
回复
代码上没有问题呀
我就是靠这个文档实现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,090

社区成员

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

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