给你一点代码,参考一下,经过测试,没有问题,请看其中的关键内容 <table width="700"
border="0" cellspacing="0" cellpadding="0">
<tr align="left">
<th><bean:message key="app.username" /></th>
<th><bean:message key="app.name" /></th>
<th><bean:message key="app.phone" /></th>
<th><bean:message key="app.email" /></th>
<th><bean:message key="app.department" /></th>
<th><bean:message key="app.role" /></th>
</tr> <!-- iterate over the results of the query 关键内容开始--> <logic:iterate id="employee" name="employees">
<tr align="left">
<td>
<bean:write name="employee" property="username" />
</td>
<td>
<bean:write name="employee" property="name" />
</td>
<td>
<bean:write name="employee" property="phone" />
</td>
<td>
<bean:write name="employee" property="email" />
</td>
<td>
<bean:write name="employee" property="department" />
</td>
<td>
<bean:write name="employee" property="rolename" />
</td>
<td>
<a href="Edit.do?username=<bean:write name="employee"
property="username" />">Edit</a>
<a href="Delete.do?username=<bean:write name="employee"
property="username" />">Delete</a>
</td>
</tr>
</logic:iterate>
<!-关键内容 结束-- >
<tr>
<td colspan="7">
<hr>
</td>
</tr>
</table>
<font size="-1" face="arial">
<a href="addemployee.jsp">Add New Employee</a>
</font>
border="0" cellspacing="0" cellpadding="0">
<tr align="left">
<th><bean:message key="app.username" /></th>
<th><bean:message key="app.name" /></th>
<th><bean:message key="app.phone" /></th>
<th><bean:message key="app.email" /></th>
<th><bean:message key="app.department" /></th>
<th><bean:message key="app.role" /></th>
</tr> <!-- iterate over the results of the query 关键内容开始--> <logic:iterate id="employee" name="employees">
<tr align="left">
<td>
<bean:write name="employee" property="username" />
</td>
<td>
<bean:write name="employee" property="name" />
</td>
<td>
<bean:write name="employee" property="phone" />
</td>
<td>
<bean:write name="employee" property="email" />
</td>
<td>
<bean:write name="employee" property="department" />
</td>
<td>
<bean:write name="employee" property="rolename" />
</td>
<td>
<a href="Edit.do?username=<bean:write name="employee"
property="username" />">Edit</a>
<a href="Delete.do?username=<bean:write name="employee"
property="username" />">Delete</a>
</td>
</tr>
</logic:iterate>
<!-关键内容 结束-- >
<tr>
<td colspan="7">
<hr>
</td>
</tr>
</table>
<font size="-1" face="arial">
<a href="addemployee.jsp">Add New Employee</a>
</font>
关键是<logic:iterate></logic:iterate>这对标签里的内容实现了循环吧数据输出<logic:iterate id="employee" name="employees">
name="employees"是Form的名字
<bean:write name="employee" property="name" />
property="name"是你显示的字段的名字
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<%@ page errorPage="error.jsp" %>
<%@ page pageEncoding="gbk" %><%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>user List</title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
</head>
<body bgcolor="#ffffaa" link="#ffcc00" alink="#ffff00" vlink="#ff9900"
marginwidth="0" marginheight="0" topmargin="0" leftmargin="0">
<tags:header title="用户列表"/>
<hr />
<jsp:useBean id="userdao" scope="request" class="com.darwin.hibernate.daoimpl.UserDAOImpl"/>
<logic:iterate id="useri" name="userdao" property="users">
<c:url var="urlGetUser" value="user.do">
<c:param name="action" value="setPassword_read" />
<c:param name="user_name" > <bean:write name="useri" property="user_name" filter="true"/> </c:param>
</c:url>
<a target="_blank" href="<c:out value='${urlGetUser}'/>" >
<bean:write name="useri" property="user_name" filter="true"/>::
</a>
<bean:write name="useri" property="user_pass" filter="true"/>
<br />
</logic:iterate>
<hr /></body>
</html>
<logic:iterate id="useri" name="userdao" property="users">
中的 id,name,property不知道传啥嘛?
晕~我想问jsp&config&class
是我所指的“完整”啊
import com.darwin.hibernate.po.*;
import net.sf.hibernate.HibernateException;
import com.darwin.hibernate.util.sys.*;
import java.util.HashMap;
import net.sf.hibernate.cfg.*;
import net.sf.hibernate.*;
import java.util.*;public class UserDAOImpl
implements UserDAO {
private User[] users = null;
private User user=null; /**
* addUser
*
* @param user User
*/
public void addUser(User user) {
try {
System.out.println("Try add user......");
HibernateUtil.add(user);
System.out.println("add finished");
}
catch (Exception ex) {
ex.printStackTrace();
}
} /**
* getUsers
*
* @return User[]
*/
public User[] getUsers() {
User[] users1 = null;
System.out.println("Startting getUsers......");
try {
Session session1 = HibernateSessionFactory.currentSession();
Transaction tx = session1.beginTransaction();
String strQry = "from User";
int i = 0;
Query query = session1.createQuery(strQry);
List list = query.list();
users1 = (User[]) list.toArray(new User[list.size()]);
tx.commit();
HibernateSessionFactory.closeSession();
}
catch (HibernateException e) {
e.toString();
}
finally { }
return (users1);
} /**
* getUserbyId
*
* @param id String
* @return User
*/
public User getUser(String user_name) {
User user = new User();
try {
System.out.println("Try get user......");
user = (User) HibernateUtil.findById(user.getClass(), user_name);
System.out.println("Get finished");
}
catch (Exception ex) {
ex.printStackTrace();
}
return user;
} /**
* updateUser
*
* @param user User
*/
public void updateUser(User user) {
try {
System.out.println("UserDAOImpl,Try update user......");
HibernateUtil.update(user);
System.out.println("UserDAOImpl, Update finished");
}
catch (Exception ex) {
ex.printStackTrace();
} }
}
sql=" select * from some tables ";
PreparedStatement stmt = conn.prepareStatement(sql);
ResultSet rs = stmt.executeQuery();
ArrayList array=new ArrayList();
while (rs.next()) {
AActionForm actionForm =new AActionForm ();
actionForm.setId(rs.getString("Id"));
actionForm.setName(rs.getString("Name"));
array.add(actionForm);
}
request.setAttribute("array", array);
在Action 的Execute方法中,我们 把这个集合用request.setAttribute("array", array)存储起来,然后在JSP页面中,我们用iterate Tag把数据循环现实出来。代码通常都是这个样子:
<logic:present name=" array " scope="request">
<logic:iterate name=" array " id=" array "
type="com.bhsky.webis.Goods">
<tr align="center">
<td class="table2">
<bean:write name=" array " property="goodsid"/>
</td>
<td class="table2">
<bean:write name=" array " property="goodsname"/>
</td>
</tr>
</logic:iterate>
</logic:present>