【发布时间】:2014-06-16 10:16:06
【问题描述】:
我有一个 jsp 页面和一个 servlet,在 servlet 中,我想从特定表中获取一些行并将它们传递给 jsp。我能够在 servlet 中检索并尝试在 jsp 中传递它们,但请不要显示任何人都在这里帮助我......
public class TimeDetail extends HttpServlet {
@SuppressWarnings("unchecked")
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
HttpSession session = request.getSession(true);
String eid = (String) session.getAttribute("eid");
int count = 0;
Connection con = ConnectionManager.getConnection();
try {
Statement st = con.createStatement();
Statement st1 = con.createStatement();
String Query = "select date, intime, outtime, eid from fulltime where eid='" + eid + "'";
ArrayList Rows = new ArrayList();
ResultSet rs = st.executeQuery(Query);
List agentList = new ArrayList();
while (rs.next()) {
ArrayList row = new ArrayList();
for (int i = 1; i <= 4; i++) {
row.add(rs.getString(i));
}
String n1 = rs.getString("date");
String n2 = rs.getString("intime");
String n3 = rs.getString("outtime");
String n4 = rs.getString("eid");
session.setAttribute("n1", n1);
session.setAttribute("n2", n2);
session.setAttribute("n3", n3);
session.setAttribute("n4", n4);
// response.sendRedirect("TimeDetail.jsp");
Rows.add(row);
}
request.getSession().setAttribute("results", Rows);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/TimeDetail.jsp");
rd.forward(request, response);
} catch (Throwable theException) {
System.out.println(theException);
}
}
}
这里是jsp代码
<tr><td>
<table width="600" height="300"align=center cellspacing=0 border="0"
<caption><h2>List of users</h2></caption>
<tr>
<th>date</th>
<th>intime</th>
<th>outtime</th>
<th>eid</th>
</tr>
<c:forEach var="user" items="${Rows.rows}">
<tr>
<td><c:out value="${user.date}" /></td>
<td><c:out value="${user.intime}" /></td>
<td><c:out value="${user.outtime}" /></td>
<td><c:out value="${user.eid}" /></td>
</tr>
</c:forEach>
</table>
</div>
</table><BR>
</fieldset>
</td></tr></table>
</td></tr>
</table>
</body>
</html>
【问题讨论】:
-
你有什么错误吗?
-
不,先生,实际上我在为 servlet 控制台打印时可以看到的值,然后我添加到列表中(我不擅长收集概念,所以可能是一些问题)并继续发送jsp 所以jsp没有显示任何错误它只是没有打印行它只显示带有标题部分的空表..
-
任何人都可以在这里帮助我......