user1263958
user1263958

Reputation: 1

Vaadin is not allowing import of external scripts

im using Vaadin and trying to import jQuery and my own script. I have extended ApplicationServlet class and redefined this method

@Override
protected void writeAjaxPageHtmlHeader(BufferedWriter page, String title,
        String themeUri, HttpServletRequest request) {

    try {
        super.writeAjaxPageHtmlHeader(page, title, themeUri, request);
        page.write("\n<script type=\"text/javascript\" src=\"/VAADIN/themes/MyTheme/js/jquery-1.7.1.js\"></script>");
        page.write("\n<script type=\"text/javascript\" src=\"/VAADIN/themes/MyTheme/js/script.js\"></script>");
        System.out.println("Added jQuery and other scripts to page header.");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

and changed in web.xml servlet class to my own, but when i get it running my scripts don't work, so i open JavaScript Console and get this two messages:

Not allowed to load local resource: file:///VAADIN/themes/MyTheme/js/jquery-1.7.1.js

Not allowed to load local resource: file:///VAADIN/themes/MyTheme/js/script.js

Why is this happening, what can i do?

Upvotes: 0

Views: 1402

Answers (1)

Henri Kerola
Henri Kerola

Reputation: 4967

The themeUri parameter provides the URI of the theme in use, so try to use that in your src attributes:

page.write("\n<script type=\"text/javascript\" src=\"" + themeUri + "/js/jquery-1.7.1.js\"></script>");

Upvotes: 2

Related Questions