logic:iterate问题
我在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;
}