以下servlet代码从数据库表中获取图像字节。
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Configuration config = new Configuration().configure();
SessionFactory sessFact = config.buildSessionFactory();
Session sess = sessFact.openSession();
pojo.File image_file = (pojo.File)sess.get(pojo.File.class, 2);
byte image_file_bytes[] = image_file.getFiles_uploaded();
// NOW WHAT ? HOW DO I MAKE IT DISPLAY IN THE BROWSER ?
}
我有
bytes
。接下来,如何在浏览器上显示图像? 最佳答案
您可以使用HttpServletResponse的OutputStream将数据写出。