0

i have written a program to retrieve a list of images(blob file) from mysql database and then calling the method inside my jsp program to display the respective images , i know i am going wrong ,so please need some guidance to explain me the way to display the image in my jsp page.

I am using a list because in my client side , i have a list of items and when i click on a respective item , the images which i have stored in my database should be retreived according to the type of item.

public List<Blob> imageCategoryList(String msg_type) {
    List imgList = new ArrayList<String>();
    try {

        Class.forName("com.mysql.jdbc.Driver");
        connection = (Connection)
        DriverManager.getConnection("jdbc:mysql://localhost:3306/image",  
        "root","root");
        state = (Statement) connection.createStatement();

        prep = (PreparedStatement) connection
                .prepareStatement("Select tt_images from timetable where   
        message_type = ?");
        prep.setString(1,msg_type);
        rSet = prep.executeQuery();
        while (rSet.next()) {
            Blob image = rSet.getBlob("tt_images");
            InputStream is = image.getBinaryStream();
            imgList.add(is);
        }

        connection.close();

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
    return imgList;
}

In my server side , i have a jsp page which has a list of items same as the client side and have a action to another jsp page in which i have written the following code, please correct my mistakes

<%
Server_Sql server_Sql = new Server_Sql();
String gcm_msg_type = request.getParameter("year_branch");
List<Blob> imgList = server_Sql.imageCategoryList(gcm_msg_type);
%>

<%
        for (int i = 0; i < imgList.size(); i++) {
    %>
    <%=imgList.get(i)%>
    <%
        }
    %>

Thanking You

arjun narahari
  • 176
  • 6
  • 26

1 Answers1

0

This is not how html works. You need to first load the (html) web page, and on that page it will have <img> tags that will will each be loaded in a separate request. You could write a JSP / Servlet to transform your blob to an image (basically all you need to do is set the content-type) but adding to the webpage itself won't work

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80