[英]Write image file in servlet by using ImageIO
I am generating an image in my servlet: 我在servlet中生成图像:
ImageIO.write(bufferedImage,"jpg" ,Outputstream)
But after deploying I am receiving an error that it can't read the input file. 但是部署后,我收到一个错误,它无法读取输入文件。
Long time ago I wrote the following code (it was taking the image stored as blob in database and writing it to the servler output): 很久以前,我编写了以下代码(它正在将存储为blob的图像获取并写入到servler输出中):
public class ImageDB extends HttpServlet {
// ...
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// ...
byte[] bytes = blob.getBytes((long)1, (int)blob.length());
ServletOutputStream out = response.getOutputStream();
out.write(bytes);
out.close(); // Close stream
// ...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.