0

*ここにJSPがあります*

<% try {
                String connectionURL = "jdbc:mysql://localhost:3306/mydb";
                Connection connection = null;
                Statement statement = null;
                ResultSet rs = null;
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                connection = DriverManager.getConnection(connectionURL, "root", "alienware");
                statement = connection.createStatement();
                String QueryString = "SELECT Warehouse_Stock.name ,Warehouse_Stock.photo from Warehouse_Stock";
                rs = statement.executeQuery(QueryString);




        %> 
        <table class = "hovered" id="info" cellpadding="15" border="2">
            <thead>
            <tr>
                 <td>Photo</td>
                <td>Product Name</td>
                <!--<td>Contact Number</td>
                <td>Remarks</td>
                <td>Email Address</td>-->

            </tr>
                </thead>
            <%
                while (rs.next()) {
            %>
            <TR>
                 <td><img src="getImageDetails.jsp?your_id=12"  /></td>
                <td><%=rs.getString(1)%></td> 

                 <%--<td><%=rs.getBlob(1)%></td>--%>
                <%-- <td><%=rs.getInt(2)%></td>
                 <td><%=rs.getString(3)%></td>
                 <td><%=rs.getString(4)%></td>--%>


            </TR>

ここにサーブレットがあります

    response.setContentType("image/jpeg");
    PrintWriter out = response.getWriter();

    int img_id = Integer.parseInt(request.getParameter("product_code"));
    DBConnectionImp db = new DBConnectionImp();
    Connection con = db.getConnection();
            ResultSet rs = null;
    PreparedStatement pstmt = null;
    OutputStream oImage;
    try {
        pstmt = con.prepareStatement("SELECT Warehouse_Stock.photo from Warehouse_Stock");
        pstmt.setInt(1, img_id);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            //byte barray[] = rs.getBytes(1);
            //byte barray[] = rs.getBytes(1);
            //response.setContentType("image/jpeg");
            ////oImage = response.getOutputStream();
            //oImage.write(barray);
           // oImage.flush();
            //oImage.close();

            Blob blob = rs.getBlob(1);

            //response.setContentType("image/jpeg");
            oImage = response.getOutputStream();
            oImage.write(blob.getBytes(1, (int) blob.length()));
            oImage.flush();
            oImage.close();



        }
    } catch (Exception ex) {
        //ex.printStackTrace();
    } finally {
        try {
            if (con != null) {
                con.close();
            }
        } catch (Exception ex) {
            // ex.printStackTrace();
        }
    }

表示されている画像がありますが、これらの画像はすべて同じです。これらの画像は実際には画像ではなく、 flash をサポートしていないブラウザーをロードしたときのように壊れた画像を表すアイコンです。ブラウザがフラッシュをサポートしていない場合に表示されるものは、私が話しているものです。しかし、それは「f」ではなく、壊れたイメージを表すアイコンです。

4

1 に答える 1