i need your help. I want to display all the images from my database (there are 6 images in there) on a jsp file. Why JSP File and not using outputreader? -> Cause i want to style the table with css in the next step so i have to do this on this special way.
Select all the pictures of the database:
public static List<Picture> displayPicture() {
List<Picture> list = new ArrayList<Picture>();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:9999/xxx", "xxx", "xxx");
String sql = "SELECT * FROM PICTURES";
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
byte[] imageData = rs.getBytes("File_Data");
String imageFileName = rs.getString("File_Name");
Picture picture = new Picture();
picture.setImageData(imageData);
picture.setImageFileName(imageFileName);
list.add(picture);
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
Now i want to save this List in setAttribute to send it to the JSP-File:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Picture> list =null;
list = DBUtils.displayPicture();
request.setAttribute("pictureList", list);
RequestDispatcher dispatcher = request.getServletContext().getRequestDispatcher("/WEB-INF/views/pictureView.jsp");
dispatcher.forward(request, response);
And finally the JSP-File:
<table>
<c:forEach items="${pictureList}" var="picture">
<tr>
<td>${picture.imageData}</td>
</tr>
</c:forEach>
So i want to display all the images in a table. At the moment it doesnt matter how the table looks like. With this code i get only a table with special numbers and letters. I think its the binary code, right? (For example: beans.Picture@22debaab or [B@3f391312])
Now where is the mistake? in the Code of the JSP-File cause i have to use
<img src="">
or something else? If this was the mistake, how should be coding this?
Thank you guys
Dear Newbie