Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.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 context.getMimeType()返回null,inputStream.available()在servlet中返回0_Java_Database_Servlets_Download - Fatal编程技术网

Java context.getMimeType()返回null,inputStream.available()在servlet中返回0

Java context.getMimeType()返回null,inputStream.available()在servlet中返回0,java,database,servlets,download,Java,Database,Servlets,Download,ResultSet result=statement.executeQuery() 我正在尝试从数据库下载数据。我在用甲骨文。我做错了什么 context.getMimeType始终返回null,inputStream.available()始终返回0 我看了其他答案,但它们与我无关。请帮忙。我找到了解决办法。其内容如下:) 我意识到获得mime并不是必需的,因为我只需要为图像文件运行代码 if (result.next()) { // gets file n

ResultSet result=statement.executeQuery()

我正在尝试从数据库下载数据。我在用甲骨文。我做错了什么

context.getMimeType始终返回null,inputStream.available()始终返回0


我看了其他答案,但它们与我无关。请帮忙。

我找到了解决办法。其内容如下:)

我意识到获得mime并不是必需的,因为我只需要为图像文件运行代码

 if (result.next()) {
                 // gets file name and file blob data
                String fileID = result.getString("image_id");
                Blob blob = result.getBlob(3);
                InputStream inputStream = blob.getBinaryStream();
                int length = (int)blob.length();
                ServletContext context = getServletContext();

                 // set content properties and header attributes for the response
                response.setContentType("image/jpeg");
                response.setContentLength(length);
                String headerKey = "Content-Disposition";
                String headerValue = String.format("attachment; filename=\"%s\"", fileID);
                 response.setHeader(headerKey, headerValue);

                 // writes the file to the client
                 OutputStream outStream = response.getOutputStream();
                 ServletOutputStream output = response.getOutputStream();
                 BufferedOutputStream bos = new BufferedOutputStream(output);
                 byte[] arr1 = blob.getBytes(1, length);
                 bos.write(arr1);

                inputStream.close();
                outStream.close();             
        }
 if (result.next()) {
                 // gets file name and file blob data
                String fileID = result.getString("image_id");
                Blob blob = result.getBlob(3);
                InputStream inputStream = blob.getBinaryStream();
                int length = (int)blob.length();
                ServletContext context = getServletContext();

                 // set content properties and header attributes for the response
                response.setContentType("image/jpeg");
                response.setContentLength(length);
                String headerKey = "Content-Disposition";
                String headerValue = String.format("attachment; filename=\"%s\"", fileID);
                 response.setHeader(headerKey, headerValue);

                 // writes the file to the client
                 OutputStream outStream = response.getOutputStream();
                 ServletOutputStream output = response.getOutputStream();
                 BufferedOutputStream bos = new BufferedOutputStream(output);
                 byte[] arr1 = blob.getBytes(1, length);
                 bos.write(arr1);

                inputStream.close();
                outStream.close();             
        }