Image in jsp through servlet -
i m not able display image on jsp page plzz dis jsp page d image inserted...`
<h4>welcome<%=rst.getstring(1)%></h4> <table> <tr><td>designation:<%=rst.getstring(4)%></td><td></td></tr> <tr><td>date of birth:<%=rst.getstring(8)%>/<%=rst.getstring(7)%>/<%=rst.getstring(6)%></td></tr> <tr><td>qualification:<%=rst.getstring(9)%></td></tr> <tr><td>full address:<%=rst.getstring(10)%><%=rst.getstring(11)%></td></tr> <tr><td>contact no:<%=rst.getstring(12)%></td></tr <tr><td><img src="image1?imgid=<%=rst.getstring(14)%>" width="60" height="60"></img></td></tr> </table>
and servlet
try {
string id1=request.getparameter("imgid"); blob image=null; byte[]imgdata=null; class.forname("com.mysql.jdbc.driver"); connectioncon=drivermanager.getconnection("jdbc:mysql://localhost:3306/regf","root","password"); statement st=con.createstatement(); resultset rs=st.executequery("select image teac userid='"+id1+"'");
}
if(rs.next()){ image = rs.getblob(18); int ln=(int) image.length(); imgdata = image.getbytes(1,ln); response.setcontenttype("image/jpeg"); outputstream o = response.getoutputstream(); inputstream readimg = rs.getbinarystream(18); int index=readimg.read(imgdata, 0,ln); response.getoutputstream().write(imgdata,0,ln); response.getoutputstream().flush(); }
}
make sure path "image1?imgid=<%=rst.getstring(14)%>" correct , follow format:
<td><img src="" alt="" border=3 height=100 width=100></img></th>.
print path on console or on page , check image exists there.
Comments
Post a Comment