使用ImageIO在servlet中写入图像文件

发布于 2025-01-07 19:35:32 字数 135 浏览 4 评论 0原文

我正在我的 servlet 中生成图像:

ImageIO.write(bufferedImage,"jpg" ,Outputstream)

但部署后我收到一条错误,指出它无法读取输入文件。

I am generating an image in my servlet:

ImageIO.write(bufferedImage,"jpg" ,Outputstream)

But after deploying I am receiving an error that it can't read the input file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安静 2025-01-14 19:35:32

很久以前,我编写了以下代码(它将图像存储为数据库中的 blob 并将其写入服务器输出):

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
// ...

  }


} 

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):

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
// ...

  }


} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文