当前位置: 动力学知识库 > 问答 > 编程问答 >

java - How to get URL of Vaadin resources path?

问题描述:

I use Eclipse + Vaadin framework.

At first I save my image into the WEB-INF folder.

Then I load this image into the FileResource variable, create Image variable and then add Image variable into Layout.

The page URL to the image resource looks like: http://servername/sitename/APP/connector/0/16/source/qwerty1.png

How to get URL in that format for use image externally?

Variable basepath returned local path: "..../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);

网友答案:

If you put the file in ...src/main/webapp/VAADIN/image.png, it should be available using for example localhost:8080/VAADIN/image.png.

分享给朋友:
您可能感兴趣的文章:
随机阅读: