简体   繁体   English

如何在JSF中用空白图像替换损坏的图像?

[英]How to replace broken images with a blank image in JSF?

I'm using the h:graphicImage tag in JSF. 我在JSF中使用h:graphicImage标记。 Is there a way to show a blank image (ie blank.jpg) if there is a broken or not found image? 如果有损坏的或找不到的图像,是否可以显示空白图像(即blank.jpg)?

There are two ways: 有两种方法:

  • client side - with javascript, see here 客户端-使用javascript, 请参阅此处
  • server side (less preferable) make an ImageServlet which takes an image url, loads it and sees if it exists. 服务器端(不太可取)使ImageServlet接收图像URL,将其加载并查看其是否存在。 If it exists, it is streamed to to client. 如果存在,则将其流式传输到客户端。 If not - the blank.jpg is streamed to the client. 如果不是,则将blank.jpg流式传输到客户端。 Verification can be done via new File(fullPathToImage).exists() , or, if the image is not on your server, using URL.openConnection() . 可以通过new File(fullPathToImage).exists() ,或者如果图像不在服务器上,则可以使用URL.openConnection()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM