注册 登录
编程论坛 J2EE论坛

[讨论]如何把从数据库读出的图片显示在叶面的某个确定位置?

yexin218 发布于 2007-01-08 13:33, 458 次点击
<%@ page contentType = "image/jpeg;charset=GB2312"%>
<%@ page import="java.sql.*"%>

<%@ page import="java.io.*"%>
<%@ page import="com.sun.image.codec.jpeg.*"%>
<%@ page import="javax.imageio.*"%>
<%@ page import="java.awt.image.*"%>

<html>
<head>
<meta http-equiv="Content-Type" content="image/jpeg;charset=GB2312">
<title>showDBImage</title>
</head>
<body>
<%
String showImage ="select * from picture_table where file_name ='02'";
Connection conn = null;
BufferedInputStream inputImage = null;

String driverName = "com.mysql.jdbc.Driver";
String dbURL = "jdbc:mysql://localhost:3306/sample_db";
String userID = "root";
String passwd = "";



try{
Class.forName(driverName).newInstance();
conn = DriverManager.getConnection(dbURL,userID,passwd);

Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(showImage);
while(rs.next()){
Blob blob = (Blob)rs.getBlob("content");
inputImage = new BufferedInputStream(blob.getBinaryStream());
}

BufferedImage image = null;
image = ImageIO.read(inputImage);
ServletOutputStream sos = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos);
encoder.encode(image);
inputImage.close();

}catch(SQLException e)
{
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
%>
</body>
</html>

上面的代码只可以把图片显示在出来,可是如果我要把他显示在叶面的某个确定位置该如何?
能给个例子最好了。
谢谢。

[此贴子已经被作者于2007-1-8 13:34:50编辑过]

1 回复
#2
无理取闹2007-01-08 13:46
那就需要html来做啊
1