java - image is not loaded from database in jsp page -


i trying display table data database jsp page, data fetched image not loaded image tab. have store image blob in table.

my jsp page follow :

<body>     <table border="1">        <%@ page import="com.*;"%>     <%         mysql myobj = new mysql();         myobj.connect();          string query="select contact_id,first_name,last_name,photo contacts";          resultset rs = myobj.getdata(query);          while(rs.next())         {                         %>             <tr>                 <td>                     <%= rs.getint(1) %>                              </td>                  <td>                     <%= rs.getstring(2).tostring() %>                 </td>                 <td>                     <%= rs.getstring(3).tostring() %>                 </td>                  <td>                     <img src="<%= rs.getstring(4) %>"  width="500" height="300" alt="data"></img>                                    </td>              </tr>         <%           }     %>       </table> </body> 

i have implement download when item name or data of second div clicked related data should downloaded.

can solve problem ?

how implement download in servlets end ?

i have write code imageservlet :

protected void doget( httpservletrequest request, httpservletresponse response) throws servletexception, ioexception      {            string id = request.getparameter("contact_id");              mysql myobj = new mysql();         myobj.connect();         printwriter out=response.getwriter();                try         {             string query="select photo contacts contact_id='"+id+"'";              resultset rs = myobj.getdata(query);              out.println(id);              blob image=null;             byte[] imgdata = null;             image= rs.getblob(1);             imgdata = image.getbytes(1, (int) image.length());             response.setcontenttype("image/gif");             outputstream o = response.getoutputstream();             o.write(imgdata);             o.flush();             o.close();              response.sendredirect("message.jsp");         }         catch (exception e)         {             e.getmessage();         }            } 

you should use servlet serve image appropriate content-type header

<img src="img-servlet?contact_id=<%= rs.getint(1) %>"  width="500" height="300" alt="data"> 

and, in servlet contact_id query param , fetch image contents


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -