del*_*980 1 java eclipse vaadin vaadin7
我使用Eclipse + Vaadin框架.
首先,我将我的图像保存到WEB-INF文件夹中.然后我将此图像加载到FileResource变量中,创建Image变量,然后将Image变量添加到Layout中.
图像资源的页面URL如下所示:http://servername/sitename/APP/connector/0/16/source/qwerty1.png
如何获取该格式的URL以便在外部使用图像?
变量basepath返回本地路径:"..../WEB-INF/qwerty1.png"
String str = (String) VaadinService.getCurrent().getBaseDirectory().
getAbsolutePath() +"/WEB-INF/qwerty1.png";
File temp = new File(str);
FileOutputStream fos = new FileOutputStream(temp);
fos.write(os.toByteArray());
fos.flush();
fos.close();
String basepath = VaadinService.getCurrent().getBaseDirectory().
getAbsolutePath() +"/WEB-INF/qwerty1.png";
FileResource resource = new FileResource(new File(basepath));
Image image2 = new Image("Image from file", resource);
addComponent(image2);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3168 次 |
| 最近记录: |