How to get a static object(s)

I’m new both in Vaadin and Eclipse, so please forgive me for such an elementary question. I got two problems:

  1. I want to have a static logout page logout.html in project named VaadinHelloWorld in folder /static. The logout process will be initiated through pressing a Button with his own listener:
public void thirdButtonClick (Button.ClickEvent event) {

(Just for proof, I got every time the text “/static/logout.html” in console after pressing the button.)
I have made a folder named “static” under the project and placed a static html file named logout.html. However, every time i get an error 404 with “The requested resource (/static/logout.html) is not available.” message. So, what’s the catch? Should I place the folder “static” place somewhere else?

  1. my second problem is also in relation with the static resorces. This time, I have tried to load an image as a logo. The class -the only one what I currently use - is in package com.example.vaadinhelloworld as follows:

package com.example.vaadinhelloworld;
import ....
public class VaadinhelloworldApplication extends Application implements
		com.vaadin.ui.Button.ClickListener {...}

The code which WORKS for getting the image is :

ClassResource res = new ClassResource("/com/example/vaadinhelloworld/pics/logo.png", mainWindow.getApplication());
mainWindow.addComponent(new Embedded ("",res));

Of course, I get the proper directory structure under Java resources/src with the file logo.png. It works fine, but I’m not able to place the picture somewhere else, for example into folder “static” mentioned above. If I do so, I will get no error, no exception, just the picture does not appear. I feel that the catch may be the same as above, but I’m not sure. Anyway I wil greatly appreciate any hint.
Greetings, Kornel

Hi, and welcome! :slight_smile:

Static content is always served from the WebContent folder in your project root, so you should move your static folder here. Everything else is hidden.

There are a few ways to make this happen: You can use an ExternalResource to serve the image from your static folder, or a ThemeResource to serve it from a theme folder. In the latter case, you need to create your own theme and theme folder (this is very easy if you just extend the default Vaadin theme, Reindeer. There is a chapter about this in the Book of Vaadin) and set the theme name for applications.

Hope this helps.

Hi, I tried the hints, they do not work. For logout page i get still 404, and for resorce (this time Externalresource) i get no picture, no error, no exception.
The folder structure is shown on next picture:
Any idea ?

new Embedded("", new ExternalResource("static/logo.png"))

That should work for the image.

As for the logout, this worked for me:

	public void init() {

Note, these can behave differently depending on your servlet mappings.

it does not work. Anyway, here’s the web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation="">
		Vaadin production mode</description>
		<servlet-name>Vaadinhelloworld Application</servlet-name>
			Vaadin application class to start</description>
		<servlet-name>Vaadinhelloworld Application</servlet-name>

But even if it’s wrong, the direct access like http://localhost:8080/static/logout.html or http://localhost:8080/WebContent/static/logout.html should work, despite the (potentially) incorrect web.xml, right? So it seems that could be a Tomcat instance conf. issue, what do you think?

Yeah, a /* mapping will most likely swallow all requests to any static content; the reason it worked in my case was that i had the following mapping:

  	<servlet-name>Test Application</servlet-name>
    <servlet-name>Test Application</servlet-name>

I played around with this a while, but couldn’t get the resources to load without mapping the application to a non-root url… Maybe someone else can chime in here?


it was taken a day or so to realise the catch: you must have /VAADIN/* mapping
in such cases, the /static/* mapping itself does not work!
After some googlework, it seems that others had similar problems:

Adding static content

Anyway, I wish you to say thank for your precious help.