以下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
。接下来我该怎么做才能在浏览器上显示图像?
答案 0 :(得分:1)
使用HttpServletResponse的OutputStream写出数据。