Я не могу отобразить свое изображение из базы данных на моей странице jsp, и я все еще не могу понять, где проблема, пожалуйста, помогите.Dispaly изображение из базы данных через сервлет на jsp
Мой сервлет:
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());
}
}
Мои 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:
Что я могу делать неправильно?
EDIT: My Web.xml огромен, но, возможно, это может быть актуально;
<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>
Ваш JSP работает в том же контексте контекста сервлета? – Unknown
Я не понимаю: P Я как бы новичок в этом. – ErrorNotFoundException
Как вы сопоставили тег img в html для сервлета? – Unknown