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

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)

Ale*_*rte 6

如果您将文件放入...src/main/webapp/VAADIN/image.png,则应该可以使用它localhost:8080/VAADIN/image.png.