【发布时间】:2010-07-07 20:46:54
【问题描述】:
我目前有一个带有文件浏览器和空白窗格的 portlet。当用户选择打开图像文件时,我想在窗格中显示图像。
但是,图像存在于 /home/myUser/images/ 中,而 portlet 存在于 /home/server/tomcat/tomcat-6.0.18/webapps/mycompany 中。它通过 Liferay 热部署一个 portlet 放置在那里。基本上,在代码中,我希望能够生成一些 html 来显示该图像。但是,我知道我不能只说
<img src='/home/myUser/images/test.jpg'/>
来自我的 portlet。因此,我考虑使用 File.createTempFile 方法将其复制到 tomcat-6.0.18/temp 目录中。我成功地将文件复制到那里,它就在那里。但是,当我现在说
<img src='/home/server/tomcat/tomcat-6.0.18/temp/test.jpg'/>
还是不能显示!注:以上文字来自:
File tempImage = File.createTempFile("","");
FileReader in = new FileReader(myImageFile);
FileWriter out = new FileWriter(tempImage);
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
out.close();
String myHtmlString = "<img src='" + tempImage.getAbsolutePath() + "'/>";
请详细说明如何解决此问题!
谢谢!
编辑:我遇到了一些关于 Image Servlet 的东西?有什么想法吗?
【问题讨论】:
标签: tomcat6