jsp 从数据库里面直接显示图片 放到网页上   Leave a comment

1. 直接写个servlet,从数据库里面读取二进制的文件内容,然后response.setContentType(“image/jpeg”); 或 response.setContentType(“image/png”); 再把这个输入流写给客户端。

outputstream outs = response.getoutputstream();
outs.write(bs);   //bs既从图据库取得的byte数组,
outs.flush();

InputStream is = rs.getBinaryStream(1);
OutputStream os = response.getOutputStream();
IOUtils.copy(is, os);
is.close();
os.close();

此servlet既为图片。

2. 用<img src=’servlet path’>来引用此servlet(图片).

Posted 2011年12月23日 by gw8310 in jsp & servlet

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: