I am unable to display my image from the database onto my jsp page and I still cannot get where the problem is please help.
My servlet:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
DBConnection db = new DBConnection();
Connection conn;
try {
conn = db.getDbConnection();
PreparedStatement ps = conn.prepareStatement("select stu_image from student_images_table where STU_REG_NO = ?");
String id = request.getParameter("studentregno");
ps.setString(1,id);
ResultSet rs = ps.executeQuery();
rs.next();
Blob b = rs.getBlob("stu_image");
response.setContentType("image/jpeg");
response.setContentLength( (int) b.length());
// response.setContentLength(10);
InputStream is = b.getBinaryStream();
OutputStream os = response.getOutputStream();
byte buf[] = new byte[(int) b.length()];
is.read(buf);
os.write(buf);
os.close();
}
catch(Exception ex) {
System.out.println(ex.getMessage());
}
}
My JSP:
<div id="bv_Image1" style="margin:0;padding:0;position:absolute;left:572px;top:31px;width:194px;height:162px;text-align:left;z-index:1;">
<img src="ProfileInquiryServlet" id="Image1" alt="" align="top" border="0" style="width:194px;height:162px;"></div>
My Display:
What could I be doing Wrong?
EDIT: My Web.xml is huge but maybe this might be relevant;
<servlet>
<servlet-name>ProfileInquiryServlet</servlet-name>
<servlet-class>com.kollega.controller.ProfileInquiryServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ProfileInquiryServlet</servlet-name>
<url-pattern>/ProfileInquiryServlet</url-pattern>
</servlet-mapping>