小编del*_*980的帖子

如何获取Vaadin资源路径的URL?

我使用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)

java eclipse vaadin vaadin7

1
推荐指数
1
解决办法
3168
查看次数

标签 统计

eclipse ×1

java ×1

vaadin ×1

vaadin7 ×1