Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java I';我试图将Base64中的一个映像转换为Blob,然后通过ServletOutputStream将其传递回,但它没有';行不通_Java - Fatal编程技术网

Java I';我试图将Base64中的一个映像转换为Blob,然后通过ServletOutputStream将其传递回,但它没有';行不通

Java I';我试图将Base64中的一个映像转换为Blob,然后通过ServletOutputStream将其传递回,但它没有';行不通,java,Java,如何将存储在数据库中的图像显示为base64代码、读取、转换为blob类型并将其作为ServletOutputStream发送回? 目前我只看到了一个黑暗的一面 我的HTML代码 <img src= url + "/EinzelBild/1"> 到目前为止,我的结果是: @GetMapping(value = "/EinzelBild/{id}") @CrossOrigin public void f_pp_bild_s(HttpSer

如何将存储在数据库中的图像显示为base64代码、读取、转换为blob类型并将其作为ServletOutputStream发送回? 目前我只看到了一个黑暗的一面

我的HTML代码

  <img src= url + "/EinzelBild/1">
到目前为止,我的结果是:

@GetMapping(value = "/EinzelBild/{id}")
@CrossOrigin
public void f_pp_bild_s(HttpServletResponse response, @PathVariable String id) throws IOException {

[...]

    if (rs.next()) {

    bild = rs.getBytes("projektbild_bin");

    byte[] name = Base64.getEncoder().encode(bild);


    Blob foto = new SerialBlob(name);

    response.reset();
    int length = (int) foto.length();
    response.setHeader("Content-Length", String.valueOf(length));
    response.setContentType("image/jpg");
    InputStream in = foto.getBinaryStream();
    

    final int bufferSize = 256;
    byte[] buffer = new byte[bufferSize];

    ServletOutputStream out = response.getOutputStream();
    while ((length = in.read(buffer)) != -1) {
                    out.write(buffer, 0, length);
    }
    
      in.close();
      out.flush();
      foto = null;

    }

}