我正在尝试通过从 mysql 获取数据来构建一个数组。该数组包括文本和图片。到目前为止一切顺利,但现在我不知道如何在 JSP 页面上显示 memolist 中的这些图片。我所能看到的只是一堆字节。让我们来看看:
我的 DBQueries 看起来像这样:
public static ArrayList<Memo> selectAllMemoList()
{
DBConnectionPool pool = DBConnectionPool.getInstance();
Connection connection = pool.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
String query = "SELECT Users.picture, Users.username, Messages.subject, Messages.date, Messages.msg_id " +
"FROM Messages, Users " +
"WHERE Messages.uid_fk = Users.uid " +
"ORDER BY date DESC";
try
{
ps = connection.prepareStatement(query);
rs = ps.executeQuery();
ArrayList<Memo> memolist = new ArrayList<Memo>();
String dbSqlTimestamp = "";
while (rs.next()) {
m.setUserpicture(rs.getString("picture"));
m.setUsername(rs.getString("username"));
m.setSubject(rs.getString("subject"));
m.setDate(dbSqlTimestamp = new SimpleDateFormat("dd-MM-yy HH:mm").format(rs.getTimestamp("date")));
m.setMessageid(rs.getInt("msg_id"));
memolist.add(m);
}
return memolist;
}
catch (SQLException e){
e.printStackTrace();
return null;
}
finally
{
DBUtil.closeResultSet(rs);
DBUtil.closePreparedStatement(ps);
pool.freeConnection(connection);
}
}
我的 MemoShowAll 看起来像这样:
@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
HttpSession session = request.getSession();
ArrayList<Memo> memolist = DBQueries.selectAllMemoList();
request.setAttribute("listmemo", memolist);
String url = "/restricted/MemoList.jsp";
// forward the request and response to the view
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
}
备忘录列表.jsp
<z:rows>
<core:forEach var="each" items="${listmemo}">
<z:row>
<img src="${each.userpicture}" border=0 >
<z:label value="${each.username}"/>
<z:label value="${each.subject}"/>
<z:label value="${each.date}"/>
</z:row>
</core:forEach>
</z:rows>
干杯,BB