servlets - Why is my image displaying a default icon in the jsp ? there is an image below -


*here 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 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> 

here servlet

    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 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();     } {         try {             if (con != null) {                 con.close();             }         } catch (exception ex) {             // ex.printstacktrace();         }     } 

you see there images showing these images same. these images not images icons represents broken image when load browser doesn't support flash . ones see when browser doesn't support flash 1 talking about. not "f" icon represents broken image.

all images loaded url

getimagedetails.jsp?your_id=12 

so url doesn't point servlet, jsp. , if pointing @ servlet, servlet expects find id of image load in parameter product_code, you're passing parameter your_id.


Comments