hibernate显示图片
来源:互联网 发布:融资租赁公司新车数据 编辑:程序博客网 时间:2024/04/30 11:35
/**
* 查询图片,在Dao中
* */
public byte[] queryPhoto(String id) {
byte[] b = null;
List l = null;
try {
session = HibernateSessionFactory.getSession();
Transaction tran = session.beginTransaction();
Query q = session
.createQuery("select new Project(ppicture) from Project where id=? and xdelete=0 ");
q.setString(0, id);
l = q.list();
System.out.println("photo size"+l.size());
Project s = (Project) l.get(0);
b = s.getPpicture();
tran.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return b;
}
/**在Action中*/
public class ProjectShowPictAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm actionform,
HttpServletRequest request, HttpServletResponse response) throws Exception {
String id=request.getParameter("id");
byte[] photo=null;
ProjectDao pd=new ProjectDao();
if(id!=null&&!"".equals(id)){
photo=pd.queryPhoto(id);
if(photo!=null){
response.setContentType("image/*");
response.getOutputStream().write(photo);
response.getOutputStream().close();
}
}
return null;
}
}
/**在jsp页面中*/
<html:form action="/projectedit" enctype="multipart/form-data">
<img src="projectshowpict.do?id=<bean:write name="projectdetailform" property="pid" />" width="100" height="100"/> </td>
- hibernate显示图片
- struts2+hibernate+sqlserver2005图片上传以及在页面显示
- Hibernate实现将图片保存至数据库、显示在页面
- java+mysql中保存图片及显示上传的图片struts+hibernate
- java+mysql中保存图片及显示上传的图片struts+hibernate
- 图片显示
- 显示图片
- 图片显示
- 图片显示
- 图片显示
- 图片显示
- 显示图片
- 图片显示
- 显示图片
- 图片显示
- 图片显示
- 显示图片
- 图片显示
- [《Twisted网络编程必备》翻译] 第3章
- java常用包
- java基础2
- 得到以及设置屏幕分辨率
- java基础3
- hibernate显示图片
- java基础4
- java基础5
- C/C++代码检视要点
- [《Twisted网络编程必备》翻译] 第4章
- struts-config.xml的例子
- 一个典型的Twisted应用程序框架
- C/C++代码检视实例
- Twisted的网络通信模型