鉴于此文件夹结构,
您的专案 |-src | `-com | `-例子 | `-BackingBean.java |-WebContent | |-meta-INF | |-WEB-INF | |-资源 | | `-图标 | | `-foo.png | `-foo.xhtml :
您可以通过采用
ExternalContext#getResourceAsStream()相对于webcontent的路径之一来获取它:
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();InputStream input = externalContext.getResourceAsStream("/resources/icons/foo.png");// ...
或通过
Resource#getInputStream()其中
Resource获得-
ResourceHandler#createResource()的
/resources相对路径:
ResourceHandler resourceHandler = FacesContext.getCurrentInstance().getApplication().getResourceHandler();InputStream input = resourceHandler.createResource("icons/foo.png").getInputStream();// ...
关于选择图像并传递其路径,只需执行以下 *** 作:
<h:graphicImage name="icons/foo.png"> <f:ajax event="click" listener="#{bean.setImage(component.name)}" /></h:graphicImage><h:graphicImage name="icons/bar.png"> <f:ajax event="click" listener="#{bean.setImage(component.name)}" /></h:graphicImage><h:commandButton value="submit" action="#{bean.saveImage}" />
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)