问:如何使用 Hibernate、MySQL 数据库从数据库检索文件/图像并在 JSP 网页中显示?

问:如何使用 Hibernate、MySQL 数据库从数据库检索文件/图像并在 JSP 网页中显示?

我需要一个代码来帮助我从 Mysql 数据库中检索我的图像/文件,并使用 HIbernate 和 Servlet JSP 将其显示在网页 (.jsp) 上。问:如何使用 Hibernate、MySQL 数据库从数据库中检索文件/图像并在 JSP 网页中显示?这是我的代码...

`/**Employee and Login Registration*/

private void saveEmp(HttpServletRequest request, 
HttpServletResponse response) throws ServletException, IOException {        
Employee emp = new Employee();  
Part part = request.getPart("image");
InputStream is = null;

if(part != null) {
    is = part.getInputStream();
    byte[] data = new byte[is.available()];
    is.read();
    emp.setImage(data);     
            
boolean status = MainServices.saveEmp(emp);
        if(status)
        {
            MainServices.saveLoginData(login);
            request.setAttribute("msg", "Form Submitted Successfully...");
            request.getRequestDispatcher("adminHome.jsp").include(request, response);
        }
        else
        {
            request.setAttribute("msg","Email or Mobile Number is already Registered with us....");
            request.getRequestDispatcher("empForm.jsp").include(request, response);
        }
    }
}

相关内容