【问题标题】:Render image with a url使用 url 渲染图像
【发布时间】:2015-09-27 18:31:25
【问题描述】:

我有一个要求,我必须在浏览器上呈现图像。给定应用程序的 url 应该在浏览器中显示图像(不下载图像)。 URL 类似于http://localhost:8080/image/render。任何已经编写的代码或任何想法都将不胜感激。

【问题讨论】:

    标签: java url servlets web-applications


    【解决方案1】:

    把它放到你的 HTML 页面中。

    <img src="http://site.domain/yourimage.extension"/>

    【讨论】:

      【解决方案2】:

      这样的事情对我有用。 在您的 servlet 中:

      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      
              ByteArrayOutputStream bout = // write your image on the stream; you can use request.getParameter(...) and so on to have it specialize
              bout.close();
              response.setContentType("png");
              response.setContentLength(bout.size());
              response.getOutputStream().write(bout.toByteArray());
              response.getOutputStream().flush();
      }
      

      【讨论】:

        猜你喜欢
        • 2022-01-18
        • 2015-06-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-15
        • 2017-08-29
        • 1970-01-01
        • 2020-05-28
        相关资源
        最近更新 更多