创建一个临时文件,页面上<img>引用这个文件。
好像没有别的方法了。
如果是应用程序还可以通过流直接创建Image.

解决方案 »

  1.   

    在网页中显示数据库中的图形的方法:举例如下:1、主Html文件:
    <html>
    <title><head>显示数据库中图形文件</head></title>
    <body>
    <h1>显示数据库中的图形文件</h1>
    <img src="http://localhost/getSketch?ID=1">
    <body>
    </html>
    2、取得图形信息的Servlet
    1中的getSketch是一个Servlet,代码如下:
    import javax.servlet.*;
    import javax.servlet.http.*;import java.io.*;
    import java.util.*;public class getSketch extends HttpServlet{
    protected void doPost(HttpServletRequest req,HttpServletResponse res) 
    throws ServletException , IOException{
    doGet(req,res);
    }

    protected void doGet(HttpServletRequest req,HttpServletResponse res) 
    throws ServletException , IOException{
    //得到参数值
    String ls_ID=req.getParameter("ID");

    java.sql.Connection con;
    java.sql.Statement stmt_Sketch;
    java.sql.ResultSet rs_Sketch;

    try{
    //连接数据库,略...
    stmt_Sketch = con.createStatement();

    rs_Sketch = stmt_Sketch.executeQuery("select sketch from sketchTable where ID="+ls_ID);
    res.setContentType("Image/gif");
    if(rs_Sketch.next()){
    ServletOutputStream out = res.getOutputStream();
    //输出二进制流
    java.io.InputStream in=rs_Sketch.getBinaryStream("sketch");
    byte b[]=new byte[1000];
    while(true){
    int readLength=in.read(b);
    if(readLength==-1)
    break;
    out.write(b,0,b.length);
    }
    out.flush();
    out.close();
    }
    rs_Sketch.close();
    stmt_Sketch.close();
    con.close();
    }catch(Exception ex){
                throw new ServletException(ex);
    }

    }
    }