在页面上使用流显示服务器上的多张图片?该怎么做?有谁知道麻烦贴下代码,图片是保存在服务器上的。

解决方案 »

  1.   

    ImageIO.write(image, "JPEG", response.getOutputStream());
      

  2.   

    <img src="<%=path %>/image01"/>
      

  3.   

    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();
      

  4.   

    上面这位兄台是不是说把下面代码放到循环中?
    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();
    但这样不会被覆盖掉吗
      

  5.   

    <img src="...">
    <img src="...">
    <img src="...">
    <img src="...">
    <img src="...">
    这个循环
      

  6.   

    shy315这位兄台,这样是不行的!它的图片是在服务器上的不是在自己机器上的!多谢关注
      

  7.   

    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();
    为什么我这样不能输出多张图片呢?请高手们帮帮忙!
      

  8.   

    可以显示多张的,因为你的img里的src可以指向“http://....jpg"的。使用循环,同上