在 Java Bean Page 中,我编写了以下代码:-
package sandip;
import java.sql;
import java.util.*;
import java.text.*;
import sandip.DataBaseConnection;
public class UserBean {
private ArrayList<Assay> assays = new ArrayList<Assay>();
private ArrayList<String> StringValue = new ArrayList<String>();
private Map<String, String> details = new HashMap<String, String>();
public void setDetails() {
Statement stmt = null;
ResultSet rs = null;
String sql = null;
DataBaseConnection obj = new DataBaseConnection();
Connection conn = null;
conn = obj.connectToDb();
try{
stmt = conn.createStatement();
sql = "SELECT `email`, `password` FROM `accounts` LIMIT 0, 12";
rs = stmt.executeQuery(sql);
while(rs.next()) {
details.put(rs.getString("password"), rs.getString("email"));
}
}catch(SQLException e) {
e.printStackTrace();
}catch(Exception ex) {
ex.printStackTrace();
}
}
public Map<String, String> getDetails() {
return this.details;
}
}
在我的jsp页面中,我使用了循环遍历:-
但它不打印任何东西。我现在应该改变什么?如果我必须做其他事情?
<h3>Hashtable iteration</h3>
<table border="1">
<c:forEach items="${userDetails.details}" var="item">
<tr>
<td align="center"><c:out value="${item.name}"/></td>
<td align="center">${item.value}</td>
</tr>
</c:forEach>
<br>
<ol>
<c:forEach items="${userDetails.details}" var="item">
<li><c:out value="${item.key}"/>=<c:out value="${item.value}"/></li>
</c:forEach>
</ol>
${item.key} 不打印任何值