数据加载中……
存入数据库中的图片,如何读出
2008年5月3日  Edited By DingDangXiaoMa
以sql server 为例:
在数据库中存储图片使用的是image 字段, 我们在使用hibernate 做映射时,把这个字段映射为byte[]
把保存到数据库中的图片,输出到页面也就以流的形式展示出来。这里以servlet 为例:
public void doGet(HttpServletRequest request, HttpServletResponse response)
            
throws ServletException, IOException {
            Map session
= ActionContext.getContext().getSession();
            response.setContentType(
"image/jpeg");
            OutputStream out 
= null;
            out 
= response.getOutputStream();
            out.write((
byte [])session.get("images"));
            out.flush();
            out.close();
    }
上述的例子是运行struts2 中session,里面存储了byte[]的images .
这样在.jsp或是html页面中真接用<image src ="" /> 在src 部分写上servlet的链接地址就可以了。

posted on 2008-05-03 09:23 叮当小马 阅读(252) 评论(0)  编辑  收藏 所属分类: JSP/JAVA


只有注册用户登录后才能发表评论。


网站导航: