首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

在jsp中图片二进制源输出到网页

2011-12-23 
在jsp中图片二进制流输出到网页求一个纯jsp二进制输出图片的例子,不是从数据库中读取,是直接从文件夹中读

在jsp中图片二进制流输出到网页
求一个纯jsp二进制输出图片的例子,
不是从数据库中读取,是直接从文件夹中读取

[解决办法]

HTML code
<%@ page info="Random Image Show"    pageEncoding="UTF-8" contentType="image/jpg"    autoFlush="true" buffer="16kb" session="false" import="java.io.FileInputStream"%><%String[] imgpaths = {    "D:/images/testimg1.jpg",    "D:/images/testimg2.jpg",    "D:/images/testimg3.jpg"};ServletOutputStream sos = response.getOutputStream();FileInputStream fis = new FileInputStream(imgpaths[(int) (Math.random() * imgpaths.length)]);byte[] buf = new byte[100];  //缓冲区大小int len = 0;while ((len = fis.read(buf)) != -1) {    sos.write(buf, 0, len);}sos.flush();sos.close();fis.close();%>
[解决办法]
探讨
HTML code<%@ page info="Random Image Show"
pageEncoding="UTF-8" contentType="image/jpg"
autoFlush="true" buffer="16kb" session="false" import="java.io.FileInputStream"
%><%
String[] imgpaths = {
"D:/images/testimg1.jpg",
"D:/images/testimg2.jpg",
"D:/images/testimg3.jpg"
};
ServletOutputStream sos = response.getOutputStream();
FileInputStream fis = new FileInputStre…

热点排行