SSH图片的上传和在页面的显示
首先,图片在hibernate的配置文件中要标示为:
?这样图片在数据库中是以BLOB形式存储的。在对应的实体类中:
?以上当form提交时,执行相应的后台操作上传便完成了。
??下载:在具体的要下载图片的jsp页面中代码如下:
?????我利用的是在action中写一个没有?forward为空的方法来获取图片的信息。具体代码:
public ActionForward showWorkerPicture(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response) {ActionForward forward = null;Java代码 String studentId = request.getParameter("id"); Long id = Long.parseLong(studentId.trim()); CourseStudentBas condition = new CourseStudentBas();//条件对象 condition.setStudentId(id); CourseStudentBas pageObject = null; //包含照片信息的队形。 try { pageObject = this.getStudentInfoService().findById(condition); byte[] imageBinary = pageObject.getPhoto(); response.setContentType("image/jpeg"); OutputStream outs = response.getOutputStream(); for (int i = 0; i < imageBinary.length; i++) { outs.write(imageBinary[i]);// 输出到页面 } outs.flush(); } catch (Exception e) { return forward; }?