Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to retrieve series of images from mysql and display them in JSP
    primarykey
    data
    text
    <p>I'm trying to build an array by fetching data from mysql. The array include text and pictures. So far everything went good but now I have no idea how to display these picture from the memolist on the JSP page. All I can see are just bunch of bytes. Let's see:</p> <p>My DBQueries looks like this:</p> <pre><code>public static ArrayList&lt;Memo&gt; 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&lt;Memo&gt; memolist = new ArrayList&lt;Memo&gt;(); 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); } } </code></pre> <p>My MemoShowAll looks like this:</p> <pre><code>@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); ArrayList&lt;Memo&gt; 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); } </code></pre> <p>MemoList.jsp</p> <pre><code>&lt;z:rows&gt; &lt;core:forEach var="each" items="${listmemo}"&gt; &lt;z:row&gt; &lt;img src="${each.userpicture}" border=0 &gt; &lt;z:label value="${each.username}"/&gt; &lt;z:label value="${each.subject}"/&gt; &lt;z:label value="${each.date}"/&gt; &lt;/z:row&gt; &lt;/core:forEach&gt; &lt;/z:rows&gt; </code></pre> <p>Cheers, BB</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload