0

I created a resource: /accounts/{accountId} which uses classes AccountServerResource.class, AccountPage.class and template accountPage.ftl.

Just for testing purpose I created a very simple template containing just one string:

<h1>Hello world</h1>

The page localhost:8111/accounts/21 is displayed correctly.

Now I want to go further and to add some more information to the resource. What I tried to do first, was adding an image to the template:

<h1>Hello, world</h1> <img src="img/user21.jpg"> 

But this time the image is not displayed. I have an error: the resource localhost:8111/accounts/21/img/user21.jpg is not found. The folder img is stored in the folder containing all *.class files and *.ftl files

How can I expose the image on my template page?

vitaliy4us
  • 483
  • 5
  • 21

1 Answers1

0
public class TestStaticFile {
    public static void main(String[] args) {
        Component component = new Component();
        Application application = new Application() {
            @Override
            public Restlet createInboundRoot() {
                Directory dir = new Directory(getContext(), "file:///d:/test");
                dir.setListingAllowed(true);
                return dir;
            }
        };
        component.getServers().add(new Server(Protocol.HTTP, 8888));
        component.getClients().add(Protocol.FILE);
        component.getDefaultHost().attach(application);
        try {
            component.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

If the path of the image is D:/test/test.jpg, now you can access with the url:http://127.0.0.1:8888/test.jpg.

You can refer to the link of the image you want to display in img tag. Restlet supports static files. Save the image in the specified folder and then refer to it in your code.

The Static files setction in restlet user guide may help.