Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- 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);
- <table>
- <c:forEach items="${pictureList}" var="picture">
- <tr>
- <td>${picture.imageData}</td>
- </tr>
- </c:forEach>
- <img src="">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement