< H:graphicImage的>没有在JSF中刷新

< H:graphicImage的>没有在JSF中刷新

问题描述:

我想在jsf web应用程序中显示一个xhtml文件中的图形图像,该文件正在针对每次运行进行更改。上传完成后,我正在显示图像。但是在上传任何图像之后发生的事情总是显示我第一次上传的图像。在刷新时显示最近上传的图像。为什么它总是显示我第一次上传的图像。如何使用 h:graphicImage 显示最近上传的图像。我正在使用servlet来显示图像。谁能帮我吗...???

I would like to display a graphic image in a jsf web application from a xhtml file that's changing for each run. I am displaying an image once the upload is done. But what happening is after uploading any image it always displays the one which I uploaded at first time. On doing refresh it displaying the recent uploaded image. Why it is always displaying an image I uploaded at first try. How could I display the most recent uploaded image with h:graphicImage. I am using servlet to display an image. Can anyone help me out...???

这是我显示图像的代码:

here is my code for displaying an image:

public void displayImage(byte[] image,HttpServletResponse response) { 
      ServletOutputStream out;
      if ( image != null ) {
      BufferedImage bufferedImage; 
           try {
                      bufferedImage = ImageIO.read(new ByteArrayInputStream(image)); 
                out = response.getOutputStream(); 
                ImageIO.write(bufferedImage, "png",out);
           } catch (IOException e) { 
                logger.info("Exception in reading the image" + e);
           }
      } else {     
           logger.info("No bytes present ");    
      }  

这是我的实际要求...
在第一个窗口我有签名框。在那里我有上传按钮。一旦完成上传,我将显示一个窗口(2),上传图像,我可以裁剪图像,以便我可以将其保存在第一个窗口的签名框。它工作正常。但是当我取消/关闭第二个窗口时会发生什么,第一个签名框仍然是空的。因此用户可以上传其他图像。在这种情况下,当我尝试上传图像时,它成功上传但是没有显示在第二个窗口上,它仍然显示我在第一次尝试上传的图像。我如何解决它...???

this is my actual requirement... In first window I have signature box. In that I have upload button.Once the upload is done then I will show an window(2) with an uploaded image there i can crop the image such that I could save it on the signature box of the first window. it is working fine. But what happens when i cancel/close the 2nd window is the signature box of 1st remains empty. So user can upload some other image. In that case, when I try to upload an image, Its successfully getting uploaded but it is not displayed on 2nd window it still the shows the image which I uploaded at first try. How do i fix it...???

告诉浏览器不要缓存图像。在第一位写入其正文之前,在servlet响应上设置以下标题:

Tell the browser to not cache the image. Set the following headers on the servlet response before the first bit is ever written to its body:

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.

为了防止硬鼻子浏览器仍然缓存它,添加一个带有时间戳的请求参数到servlet URL 。

To prevent hard-nosed browsers from still caching it, add a request parameter with a timestampto the servlet URL.

<h:graphicImage value="imageServlet?id=#{bean.imageId}&amp;t=#{now.time}" />

其中#{now} 已注册在 faces-config.xml 中,如下所示:

Where #{now} is been registered in faces-config.xml as follows:

<managed-bean>
    <managed-bean-name>now</managed-bean-name>
    <managed-bean-class>java.util.Date</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>