java 使用流 显示多张图片 在页面上使用流显示服务器上的多张图片?该怎么做?有谁知道麻烦贴下代码,图片是保存在服务器上的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ImageIO.write(image, "JPEG", response.getOutputStream()); <img src="<%=path %>/image01"/> response.setContentType("image/jpeg; charset=GBK");ServletOutputStream out= response.getOutputStream();FileInputStream in= new FileInputStream(fileinputstream);byte[] buffer = new byte[1024];while ((int n = in.read(buffer)) != -1) { out.write(buffer, 0, n);}out.flush();out.close();in.close(); 上面这位兄台是不是说把下面代码放到循环中?response.setContentType("image/jpeg; charset=GBK");ServletOutputStream out= response.getOutputStream();FileInputStream in= new FileInputStream(fileinputstream);byte[] buffer = new byte[1024];while ((int n = in.read(buffer)) != -1) { out.write(buffer, 0, n);}out.flush();out.close();in.close();但这样不会被覆盖掉吗 <img src="..."><img src="..."><img src="..."><img src="..."><img src="...">这个循环 shy315这位兄台,这样是不行的!它的图片是在服务器上的不是在自己机器上的!多谢关注 response.setContentType("image/jpeg; charset=GBK");//得到输出流ServletOutputStream stream = response.getOutputStream();FileInputStream in =null;for(int i=0;i<list.size();i++){ System.out.println("i= "+i); //取得服务器上的图片路径 String newFilePath = GetProperties.cutResultPath + "new"+i + fileName; File inputFile = new File(newFilePath); //得到输入流 in = new FileInputStream(inputFile); if (in != null) { byte[] b = new byte[1024]; int len = 0; while ((len = in.read(b)) != -1) { //写入输出流 stream.write(b, 0, len); } }}stream.flush();//关闭输出流stream.close();//关闭输入流in.close();为什么我这样不能输出多张图片呢?请高手们帮帮忙! 可以显示多张的,因为你的img里的src可以指向“http://....jpg"的。使用循环,同上 oracle 分页排序,ssi jdbc深入理解问题 关于jsp循环1000次而产生的奇怪结果(比较速度差异) 关于邮件系统的映射问题。求救啊。。。 急求 谁做过SSH+DhtmlXtree实现的树 JS中怎么循环出checkbox所取的的值 关于一个上传的,很变态的问题,请大家帮忙解决 一个字符串分割,并存放到不同变量里去。 javascript小问题!(在线等) 用struct2,用户登录和查询表单 提交表单的页面如何实现打开新窗口提交,原窗口跳转到另一页面? myeclipse9导入jquery.js文件出错 何解
ServletOutputStream out= response.getOutputStream();
FileInputStream in= new FileInputStream(fileinputstream);
byte[] buffer = new byte[1024];
while ((int n = in.read(buffer)) != -1) {
out.write(buffer, 0, n);
}
out.flush();
out.close();
in.close();
response.setContentType("image/jpeg; charset=GBK");
ServletOutputStream out= response.getOutputStream();
FileInputStream in= new FileInputStream(fileinputstream);
byte[] buffer = new byte[1024];
while ((int n = in.read(buffer)) != -1) {
out.write(buffer, 0, n);
}
out.flush();
out.close();
in.close();
但这样不会被覆盖掉吗
<img src="...">
<img src="...">
<img src="...">
<img src="...">
这个循环
//得到输出流
ServletOutputStream stream = response.getOutputStream();
FileInputStream in =null;
for(int i=0;i<list.size();i++){
System.out.println("i= "+i);
//取得服务器上的图片路径
String newFilePath = GetProperties.cutResultPath + "new"+i + fileName;
File inputFile = new File(newFilePath);
//得到输入流
in = new FileInputStream(inputFile);
if (in != null) {
byte[] b = new byte[1024];
int len = 0;
while ((len = in.read(b)) != -1) {
//写入输出流
stream.write(b, 0, len);
}
}
}
stream.flush();
//关闭输出流
stream.close();
//关闭输入流
in.close();
为什么我这样不能输出多张图片呢?请高手们帮帮忙!