tapestry显示image

https://github.com/balsarori

public class ImageTest {
    @Inject
    private ComponentResources _resources;

    public Link getChart3() {
        return _resources.createEventLink("chart", false, null);
    }
    
    public StreamResponse onChart(){
        return new StreamResponse() {
            public String getContentType(){
                return "image/png";
            }
            public InputStream getStream() throws IOException {
                   try {
                       return new ClasspathResource("diagrams/vacation.png").openStream();
                   } catch (IOException ex) {
                       throw new RuntimeException("Cannot read image file.", ex);
                   } 
            }
            public void prepareResponse(Response response){}
        };
    }
}

ImageTest.tml文件

<html
    xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
    xmlns:p="tapestry:parameter">
    <header>
      <title>image display</title>
    </header>
    <body>
        <img src="${chart3}"/>
    </body>
</html>

你可能感兴趣的:(tapestry显示image)