1
我设法将图像作为Blob存储在我的mysql数据库中。 (我也使用休眠) 现在我想加载该图像并将其发送到一个jsp页面,以便用户可以查看图像。使用struts 2和休眠在jsp页面显示Blob(图像)
这是我的支柱2 Action类
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以显示存储的图像?
如果问题得到解决,则将答案标记为接受。 – ManuPK 2012-04-09 13:53:34