使用 Tapestry5 在我的应用程序外部显示图像
我正在使用 Tapestry 开发我的第一个项目,除了图像之外,我即将完成。
我想要什么?我只需要在应用程序外部显示图像,例如:/ home/app/images/image.jpg
我尝试了什么? 我一直在“谷歌搜索”并阅读 Tapestry5 论坛,我发现了这个:http://wiki.apache.org/tapestry/Tapestry5HowToStreamAnExistingBinaryFile
我按照步骤操作,创建类,但我需要要在另一个页面上显示嵌入的图像(因此我无法使用 ImagePage),我尝试了以下操作:
在页面 java 类
public StreamResponse getImage() {
InputStream input = DetallesMultimedia.class
.getResourceAsStream("/home/santi/Escritorio/evolution-of-mario.jpg"); //On application, i will retrieve this from DB
return new JPEGInline(input,"hellow");
}
在页面上template
...
<img src="${image}" alt:image/>
...
or
...
${image}
...
显然,这不起作用,我真的不知道该怎么做。我读到了有关在事件上加载图像的信息(在该事件上返回 OutputStream,如上面链接的 HowTo 中所述),但我的英语很差(我相信您已经注意到)并且我不太明白我该如何这样做。
你能帮我一下吗?
谢谢大家。
I am developing my first project with Tapestry and I am about to finish, except for the images..
What do I want? I just need to display an image outside my application, example: /home/app/images/image.jpg
What did I try? I have been "googling" and reading Tapestry5 forums, I found this: http://wiki.apache.org/tapestry/Tapestry5HowToStreamAnExistingBinaryFile
I followed the steps, creating classes but I need to display the image embed on another page (so I can't use ImagePage), I tried this:
On page java class
public StreamResponse getImage() {
InputStream input = DetallesMultimedia.class
.getResourceAsStream("/home/santi/Escritorio/evolution-of-mario.jpg"); //On application, i will retrieve this from DB
return new JPEGInline(input,"hellow");
}
On page template
...
<img src="${image}" alt:image/>
...
or
...
${image}
...
Obviusly, this didn't work and I really don't know how can I do it. I read about loading the image on an event (returning the OutputStream on that event, as it's said in the HowTo linked above) but my english is so bad (I am sure you already noticed) and I don't understand well how can I do that.
Could you help me please?
Thanks you all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从未见过维基页面上的示例。下面是一些关于如何使用 StreamResponse 在类路径上加载图像的代码。
在您的模板中:
I've never seen the examples as on the wiki page. Below some code on how to load an image on the classpath though using a StreamResponse.
In your template: