【发布时间】:2012-04-20 17:58:14
【问题描述】:
我设法将图像作为 Blob 存储在我的 mysql 数据库中。 (我也在使用休眠) 现在我正在尝试加载该图像并将其发送到 jsp 页面上,以便用户可以查看该图像。
这是我的 struts 2 动作类
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.Blob; import org.hibernate.Hibernate; import domain.post.image.Image; public class FileUploadAction { private File file; @SuppressWarnings("deprecation") public String execute() { try { System.out.println(file.getPath()); Image image = new Image(); FileInputStream fi = new FileInputStream(file); Blob blob = Hibernate.createBlob(fi); image.setImage(blob); image.save(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return "success"; } public File getFile() { return file; } public void setFile(File file) { this.file = file; }
这是我的图像类
public class Image extends AbsDBObject<Object> { private static final long serialVersionUID = 1L; private static Logger logger = Logger.getLogger(Image.class); private Blob image; private String description; //Getters and Setters }
您能告诉我应该在动作类、jsp 页面和 struts.xml 中添加什么以显示存储的图像吗?
【问题讨论】:
-
如果问题已解决,请将答案标记为已接受。
标签: java hibernate jakarta-ee struts2 web