我无法将数据库中的图像显示到我的 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>
我的显示器:
我可能做错了什么?
编辑: 我的 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>